Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all sms from inbox programmatically in android?

Tags:

android

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?

like image 270
Jaydeepsinh Jadeja Avatar asked Feb 25 '12 10:02

Jaydeepsinh Jadeja


People also ask

How do I clean up SMS inbox on Android?

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.

How can I delete bulk SMS in android?

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.

Can we delete an SMS in Android before it reaches the inbox?

@kakopappa: Yes, as mentioned in the answer it works from Android 1.6+.


2 Answers

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;
like image 96
Mariusz Jamro Avatar answered Sep 21 '22 15:09

Mariusz Jamro


//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"});
like image 31
Tosun Can Avatar answered Sep 21 '22 15:09

Tosun Can