Set sms as read in Android

你离开我真会死。 提交于 2019-12-17 20:48:06

问题


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!


回答1:


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
}



回答2:


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.



来源:https://stackoverflow.com/questions/6059604/set-sms-as-read-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!