Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set sms as read in Android

Tags:

android

sms

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 application, but from my app. How can I do? Thanks!

like image 624
pindol Avatar asked May 19 '11 13:05

pindol


People also ask

Is there a way to mark a text as unread on Android?

Tap and hold on a chat. Tap to select any other chats. Tap Menu at the top. Select Mark as unread.


2 Answers

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.

like image 68
Michalsx Avatar answered Sep 23 '22 15:09

Michalsx


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
}
like image 23
hoferm Avatar answered Sep 21 '22 15:09

hoferm