android 删除消息无效

android delete message not working

我想在消息到达时删除消息,我设置了广播监听器,以下是代码示例:

    Uri uriSMSURI = Uri.parse("content://sms/inbox/");
    Cursor cur = c.getContentResolver().query(uriSMSURI, null, null, null, null);

    while (cur.moveToNext()) 
    {


           for(int i = 0 ; i <uptoallmessage_n;i++)
           {


               if(matchednumber)
               {
                   long s = cur.getLong(1);
                   String str = "content://sms/conversations/" + s;
                   Log.e("msg", str);

                   try 
                   {
                       c.getContentResolver().delete(Uri.parse(str), null, null);
                   } catch (Exception e) 
                   {
                       e.printStackTrace();
                   }
               }
           }

    }

根据权限我已经设置

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_SMS" />

按照我进入的 uri logcat

  07-16 18:14:26.069: E/msg(25477): content://sms/conversations/679
  07-16 18:14:26.072: E/msg(25477): content://sms/conversations/679
  07-16 18:14:26.076: E/msg(25477): content://sms/conversations/679
  07-16 18:14:26.079: E/msg(25477): content://sms/conversations/679
  07-16 18:14:26.082: E/msg(25477): content://sms/conversations/679
  07-16 18:14:26.084: E/msg(25477): content://sms/conversations/679
  07-16 18:14:26.086: E/msg(25477): content://sms/conversations/679

提前致谢,

代码在 Android 4.4 之前工作正常,根据 google 策略只有默认应用程序可以删除消息。如果你想让你的应用程序默认,那么你需要开发完整的短信应用程序,并且可以根据 google 文档将其设为默认。