Hello I try to mark a SMS as read on android. I have the following code:
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);
}
The execution of the code happens here:
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());
}
}
I have tried all possible solutions. Why am i not able to set this sms as read? Where is the problem?