I build an android SMS app and i want to received sms from my smsReceiver everything is going to fine i used the flowing code for on conversation activity and this method perfectly worked but when I go back my default SMS App is marked the messages unread and it show notification on icon as unread I don't how i changed the status of default message app to read status true I am using huawei G610 for testing and API 17 jelly beans
public static void markMessageRead(Context context, String number, String body) {
Uri uri = Uri.parse("content://sms/inbox");
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
try {
while (cursor.moveToNext()) {
String address =(cursor.getString(cursor.getColumnIndex("address")));
int read = cursor.getInt(cursor.getColumnIndex("read"));
if (address.equals(number) && read== 0) {
if (cursor.getString(cursor.getColumnIndex("body")).startsWith(body)) {
String SmsMessageId = cursor.getString(cursor.getColumnIndex("_id"));
ContentValues values = new ContentValues();
values.put("read", 1);
int iii =context.getContentResolver().update(Uri.parse("content://sms/inbox"), values, "_id=" + SmsMessageId, null);
Log.i("update", iii+"");
return;
}
}
}
} catch(Exception e) {
Log.e("Mark Read", "Error in Read: "+e.toString());
}
}