0

I would like to delete message when message arrives, I have setup broadcast listener, following is code sample:

    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();
                   }
               }
           }

    }

following permission i have setup

<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" />

Following uri i am getting in 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

Thanks in Advance,

Adarsh
  • 270
  • 1
  • 3
  • 16
  • Ref : http://stackoverflow.com/questions/8614211/deleting-android-sms-programatically –  Jul 16 '15 at 12:48
  • Thank you for your reply, how can I make my app as default app or is there any other way to delete message ? – Adarsh Jul 16 '15 at 12:50
  • Thanks a lot I have read complete article and found all details, thanks – Adarsh Jul 16 '15 at 13:24
  • Please answer your own question and accept your answer. That will help others who have the same problem and will also remove this question from the list of unanswered questions. Thanks! – David Wasser Jul 19 '15 at 20:48
  • Thanks for your comment, I have added answer and marked too. – Adarsh Jul 21 '15 at 12:14

1 Answers1

0

Code is working fine before Android 4.4, As per google policy only default application can delete message. If you wish to make your apps default then you need to develop complete sms application and can make it default as per google documentations.

Adarsh
  • 270
  • 1
  • 3
  • 16