I am working on an application in which I want to delete all SMS from inbox. For that I have used the following code.
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = getContentResolver().query(uriSms, null,null,null,null);
int id = c.getInt(0);
int thread_id = c.getInt(1); //get the thread_id
getContentResolver().delete(Uri.parse("content://sms/conversations/" + thread_id),null,null);
This code does not work. Is there any way to do the same?
Delete individual text messagesTap the conversation. Touch and hold the message you want to delete. Optional: To delete multiple messages, touch and hold the first message, then tap more messages. Tap Delete to confirm.
Delete multiple messages at once on Android Step 1: Tap to open Messages. Step 2: Tap and hold on the first message you want to delete. A checkmark should appear to its left. Step 3: Tap on all other messages you want to be deleted.
@kakopappa: Yes, as mentioned in the answer it works from Android 1.6+.
The delete uri is "content://sms/" + id;
Uri inboxUri = Uri.parse("content://sms/inbox");
int count = 0;
Cursor c = context.getContentResolver().query(inboxUri , null, null, null, null);
while (c.moveToNext()) {
try {
// Delete the SMS
String pid = c.getString(0); // Get id;
String uri = "content://sms/" + pid;
count = context.getContentResolver().delete(Uri.parse(uri),
null, null);
} catch (Exception e) {
}
}
return count;
//delete all call logs
Uri callLog = Uri.parse("content://call_log/calls");
int rs1 = getContentResolver().delete(callLog, null, null);
//delete all sms
Uri inboxUri = Uri.parse("content://sms/");
int rs2 = getContentResolver().delete(inboxUri, Sms._ID + "!=?", new String[]{"0"});
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