Is it possible in Android to detect that a message has been deleted from the message store in Android programatically. If yes, do we have access to information that which SMS was deleted.
The best I can think of is that you can register a ContentObserver on the SMS/MMS content provider (I think it is content://mms-sms) and whenever a change occurs you'll get a callback. Note that you will need to scan the ContentProvider and save its current state and then every time there is a change you will need to search the ContentProvider to figure out WHAT changed: there is no pre-packaged way to be informed that the user deleted a specific message.
Simply use this code
try {
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = context.getContentResolver().query(
uriSms,
new String[] { "_id", "thread_id", "address", "person",
"date", "body" }, "read=0", null, null);
if (c != null && c.moveToFirst()) {
do {
long id = c.getLong(0);
long threadId = c.getLong(1);
String address = c.getString(2);
String body = c.getString(5);
String date = c.getString(3);
if (message.equals(body) && address.equals(number)) {
// mLogger.logInfo("Deleting SMS with id: " + threadId);
context.getContentResolver().delete(
Uri.parse("content://sms/" + id), "date=?",
new String[] { <your date>});
Log.e("log>>>", "Delete success.........");
}
} while (c.moveToNext());
}
} catch (Exception e) {
Log.e("log>>>", e.toString());
}
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