2

Hello I am trying to mark all SMS as read on android I tried all pisible solution but I couldn't seems like I have something wrong I tried the follwing solutions

here is my code

     protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_smslist);
            markSmsAsRead();
            setSMSRead();
    }

 public void markSmsAsRead() {

        Uri uri = Uri.parse("content://sms/inbox");
        String selection = "read = ?";
        String[] selectionArgs = {"0"};

        ContentValues values = new ContentValues();
        values.put("read", true);
        Context context = getApplicationContext();
        context.getContentResolver().update(uri, values, selection, selectionArgs);
    }
    public void setSMSRead()
    {
        ContentValues values = new ContentValues();
        values.put("read", true);
       // String where = "read = 0";
       // String where = "_id < 100000";
        Context context = getApplicationContext();
        context.getContentResolver().update(Uri.parse("content://sms/inbox"), values, "_id<" + "100000", null);

    }
Community
  • 1
  • 1
John Donvan
  • 554
  • 8
  • 22
  • Possible duplicate of [How to mark all text messages as read on Android?](http://stackoverflow.com/questions/33678063/how-to-mark-all-text-messages-as-read-on-android) – fejd Dec 28 '15 at 07:57

1 Answers1

2

In order to mark sms's as read your app must be default SMS application

dnkilic
  • 218
  • 2
  • 11
  • 2
    +1 This is correct. See http://android-developers.blogspot.ru/2013/10/getting-your-sms-apps-ready-for-kitkat.html – FCA Mar 05 '16 at 05:34