您好,我尝试将SMS标记为在Android上已读取。我有以下代码:
public void setRead(int position, String smsMessageId) {
smsBody.get(position).status=true;
ContentValues values = new ContentValues();
values.put("read", true);
context.getContentResolver().update(Uri.parse("content://sms/inbox"),
values, "_id=" + smsMessageId, null);
}
代码的执行在这里发生:
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
try {
SMSItem smsMessageStr = (SMSItem) arrayAdapter.getItem(pos);
if (smsMessageStr.status == false) {
// String smsMessageId = ((SmsArrayAdapter)
// arrayAdapter).getId(pos);
((SmsArrayAdapter) arrayAdapter).setRead(pos, smsMessageStr.ID);
Toast.makeText(this, "ID is " + smsMessageStr.ID, Toast.LENGTH_LONG)
.show();
}
Intent intent = new Intent(SmsActivity.this,
ShowIndividualSMS.class);
intent.putExtra("SMS", smsMessageStr.sms);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "exception is " + e.getMessage(),
Toast.LENGTH_LONG).show();
Log.e("TAG", e.getMessage());
}
}
我已经尝试了所有可能的解决方案。为什么我无法将此短信设置为已读?问题出在哪里?
最佳答案
尝试这个,
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
}
也用
ContentValues values = new ContentValues();
values.put("read",true);
getContentResolver().update(Uri.parse("content://sms/inbox"),values,
"_id="+SmsMessageId, null);
其中id是消息ID。
关于android - 如何将短信标记为已读,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32712884/