I want to delete 1 SMS from my android device programatically. Here is the code I am currently using.
private void DeleteSMS(int SmsId){
Cursor c = getContentResolver().query(Uri.parse("content://sms/"),new String[] {"_id", "thread_id", "address", "body" }, null, null, null);
while (c.moveToNext()) {
try {
int pid = Integer.valueOf(c.getString(0));; // Get id;
String smsMessage = c.getString(3);
if (pid == SmsId)
{
String uri = "content://sms/"+pid;
int rows = getContentResolver().delete(Uri.parse(uri), null, null);
Toast.makeText(context, rows+" Message Deleted", Toast.LENGTH_LONG).show();
break;
}
} catch (Exception e) {
Log.v("exception","occurred");
}
}
}
After executing the delete statement with getContentResolver().delete
, it will return the rows affected as 0.