Android Studio(按特定编号删除发送和接收的短信)

少年恃险若平地,独倚长剑凌清秋。这篇文章主要讲述Android Studio:按特定编号删除发送和接收的短信相关的知识,希望能为你提供帮助。
我想知道如何通过特定号码删除发送和接收的SMS。我的应用程序正在与其他设备的GSM模块连接,并发送和接收SMS消息。我想删除这些短信。下面是我的代码:

@Override public void onReceive(Context context, Intent intent) { if (Objects.equals(intent.getAction(), SMS_RECEIVED)) { String smsSender = ""; String smsBody = ""; if (Build.VERSION.SDK_INT > = Build.VERSION_CODES.KITKAT) { StringBuilder smsBodyBuilder = new StringBuilder(); for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) { smsSender = smsMessage.getDisplayOriginatingAddress(); smsBodyBuilder.append(smsMessage.getMessageBody()); } smsBody = smsBodyBuilder.toString(); } else { Bundle smsBundle = intent.getExtras(); if (smsBundle != null) { Object[] pdus = (Object[]) smsBundle.get("pdus"); if (pdus == null) { // Display some error to the user return; } SmsMessage[] messages = new SmsMessage[pdus.length]; StringBuilder smsBodyBuilder = new StringBuilder(); for (int i = 0; i < messages.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); smsBodyBuilder.append(messages[i].getMessageBody()); } smsBody = smsBodyBuilder.toString(); smsSender = messages[0].getOriginatingAddress(); } }if (smsSender != null) { if (smsSender.equals(serviceProviderNumber) & & smsBody.startsWith(serviceProviderSmsCondition)) { this.pdCanceller.removeCallbacks(this.progressRunnable); this.message = smsBody; context.unregisterReceiver(broadcastReceiver); progressDialog.cancel(); SmsReceiverDialog smsReceiverDialog = new SmsReceiverDialog(this.activity, this.context, this.message); checkCommand(smsBody, smsReceiverDialog); // call correctly function from list context.getContentResolver().delete(Uri.parse("content://sms/"), "address=?", new String[]{smsSender}); } } } }

源代码正在捕获SMS消息。我对where子句有疑问。删除短信无效。
答案[来自deleting-android-sms-programmatically的“ Maksim Dmitriev”答案的积分
[请注意,您无法在装有android 4.4的设备上删除SMS消息。
此外,系统现在仅允许默认应用程序将消息数据写入提供者,尽管其他应用程序可以随时读取。
http://developer.android.com/about/versions/kitkat.html
【Android Studio(按特定编号删除发送和接收的短信)】如果尝试,不会引发异常;什么都不会被删除。

    推荐阅读