将sms设置为在Android中读取

pin*_*dol 5 sms android

在我的应用程序中,我需要读取仅来自一个数字的短信,当我收到它时,我需要将其设置为自动读取,而不是在sms android应用程序中设置,而是从我的应用程序.我能怎么做?谢谢!

Mic*_*lsx 14

让我更新一下:

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

SmsMessageId是_id消息,您可以在SMS数据库中找到它.


小智 3

一个简短的例子:

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
}
Run Code Online (Sandbox Code Playgroud)