I can catch sms, can see sender phone, body, I can abortBroadcast if I don't like this sms, but I don't know how to just mark this sms as read, that user can readit in box later. Any ideas how I can do this?
Receive SMS messages with a broadcast receiver. To receive SMS messages, use the onReceive() method of the BroadcastReceiver class. The Android framework sends out system broadcasts of events such as receiving an SMS message, containing intents that are meant to be received using a BroadcastReceiver.
This might help you :
private 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()) {
if ((cursor.getString(cursor.getColumnIndex("address")).equals(number)) && (cursor.getInt(cursor.getColumnIndex("read")) == 0)) {
if (cursor.getString(cursor.getColumnIndex("body")).startsWith(body)) {
String SmsMessageId = cursor.getString(cursor.getColumnIndex("_id"));
ContentValues values = new ContentValues();
values.put("read", true);
context.getContentResolver().update(Uri.parse("content://sms/inbox"), values, "_id=" + SmsMessageId, null);
return;
}
}
}
}catch(Exception e)
{
Log.e("Mark Read", "Error in Read: "+e.toString());
}
}
Since Android 4.4 KitKat the only app can modify sms data - SMS-app that was set as default
only the app that receives the SMS_DELIVER_ACTION broadcast (the user-specified default SMS app) is able to write to the SMS Provider defined by the android.provider.Telephony class and subclasses
More info can be found here: http://android-developers.blogspot.ru/2013/10/getting-your-sms-apps-ready-for-kitkat.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With