I'm trying to develop app in which my requirement is to delete sms from particular no. both outgoing and incoming message. right now i coded for incoming SMS as below. code is running fine to delete message but messages are not getting deleted in real.
this is for incoming messages only.
also please tell me how to delete outgoing messages also.
void deleteMessage(Context context){
String no="55778866";
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);
String address = c.getString(2);
long threadId = c.getLong(1);
String body = c.getString(5);
String date = c.getString(3);
Log.e("log>>>",
"0--->" + c.getString(0) + "1---->" + c.getString(1)
+ "2---->" + c.getString(2) + "3--->"
+ c.getString(3) + "4----->" + c.getString(4)
+ "5---->" + c.getString(5));
Log.e("log>>>", "date" + c.getString(0));
ContentValues values = new ContentValues();
values.put("read", true);
getContentResolver().update(Uri.parse("content://sms/"),
values, "_id=" + id, null);
Log.e("SMS Match >>>>","address >>>>"+address+" no. >>>>"+no+" match >>>> "+address.equals(no));
if (address.equals(no)) {
try{
context.getContentResolver().delete(
Uri.parse("content://sms/" + id), "date=?",
new String[] { c.getString(4) });
Log.e("log>>>", "Delete success.........");
Toast.makeText(getApplicationContext(),"SMS Deleted",Toast.LENGTH_SHORT).show();
}catch (Exception e){
Log.e("DELETE >>>",e.getMessage());
}
}
} while (c.moveToNext());
}
} catch (Exception e) {
Log.e("log>>>", "ERROR "+e.toString());
}
}