0

I want to delete 1 SMS from my android device programatically. Here is the code I am currently using.

private void DeleteSMS(int SmsId){
         Cursor c = getContentResolver().query(Uri.parse("content://sms/"),new String[] {"_id", "thread_id", "address", "body" }, null, null, null);
         while (c.moveToNext()) {
            try {
                    int pid = Integer.valueOf(c.getString(0));; // Get id;
                    String smsMessage = c.getString(3);
                    if (pid == SmsId)
                    {
                        String uri = "content://sms/"+pid;
                        int rows = getContentResolver().delete(Uri.parse(uri), null, null);
                        Toast.makeText(context, rows+" Message Deleted", Toast.LENGTH_LONG).show();
                        break;
                    }
            } catch (Exception e) {
                    Log.v("exception","occurred");
            }
         }
    }

After executing the delete statement with getContentResolver().delete, it will return the rows affected as 0.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
SHIDHIN TS
  • 1,557
  • 3
  • 26
  • 58
  • possible duplicate of [Deleting Android SMS programatically](http://stackoverflow.com/questions/8614211/deleting-android-sms-programatically) – Maveňツ Mar 31 '15 at 07:03

1 Answers1

1

Pls check this answer https://stackoverflow.com/a/8851644/3020568

Your app should be configured as default SMS app for dealing with sms - above 4.4

Check this

http://android-developers.blogspot.in/2013/10/getting-your-sms-apps-ready-for-kitkat.html

Community
  • 1
  • 1
Deniz
  • 12,332
  • 10
  • 44
  • 62