Set sms as read in Android

后端 未结 2 1818
情话喂你
情话喂你 2020-12-11 19:28

In my application I need to read sms coming from only a number, and when i receive it I need to set it as read automatically, without setting it in the sms android applicati

相关标签:
2条回答
  • 2020-12-11 19:57

    A short example:

    Uri uri = Uri.parse("content://sms/inbox");
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
    while (cursor.moveToNext()) {
      // Retrieve sms
      // see column "address" for comparing
    
      // Then update the sms and set the column "read" to 1
    }
    
    0 讨论(0)
  • 2020-12-11 20:10

    Let me update this:

    ContentValues values = new ContentValues();
    values.put("read",true);
    getContentResolver().update(Uri.parse("content://sms/"),values, "_id="+SmsMessageId, null);
    

    SmsMessageId is _id of message, which you find in SMS database.

    0 讨论(0)
提交回复
热议问题