0

I am trying to mark all messages as read. Here is my code

       final Uri SMS_INBOX = Uri.parse("content://sms/inbox");

    Cursor cursor = context.getContentResolver().query(SMS_INBOX, null, "read=0", null, null);

    while (cursor.moveToNext()) {

        String SmsMessageId = cursor.getString(cursor.getColumnIndex("_id"));
        ContentValues values = new ContentValues();
        values.put("read", true);
        int result=context.getContentResolver().update(Uri.parse("content://sms/inbox"), values, null, null);
        Log.v("Sms message id ----->",SmsMessageId+" and result --->"+result);

    }
    cursor.close();

but update() returns 0

    int result=context.getContentResolver().update(Uri.parse("content://sms/inbox"), values, "_id="+SmsMessageId , null);

also returns 0 and here permissions

  <uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Mustafa
  • 1
  • 3
  • Since KitKat, only the app selected as the default messaging app has write access to the Provider. Other apps cannot save, delete, or modify any messages. – Mike M. Aug 13 '17 at 22:42
  • Ok thank you. is it impossible to change status of the message(read/unread) in any way? – Mustafa Aug 13 '17 at 22:51
  • 1
    I can think of three ways, off the cuff: 1) Your app is the default messaging app. 2) The device is rooted. 3) Your app is on _exactly_ KitKat (4.4), and you exploit the security hole that is present in that version _only_, by which a non-default app can get write access to the Provider. In other words, no way that is widely applicable and reliable. – Mike M. Aug 13 '17 at 22:55
  • 1
    Got it. Thank you so much – Mustafa Aug 13 '17 at 22:57

0 Answers0