Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete draft SMS in android

Tags:

android

I want to delete draft SMS. I am able to delete inbox SMS. How can i delete draft SMS ?

Thanks in advance.

like image 483
unflagged.destination Avatar asked Mar 17 '26 03:03

unflagged.destination


1 Answers

Try the code below

private void deleteDrafts() {
    /*
     * This will delete all drafts from Messaging App.
     */
    try { 
        Uri uriSms = Uri.parse("content://sms/draft"); 
        Cursor c = getContentResolver().query(uriSms, new String[] { "_id", "thread_id", "address", 
                "person", "date", "body" }, null, null, null); 

        if (c != null && c.moveToFirst()) { 
            do { 
                long id = c.getLong(0); 
                getContentResolver().delete(Uri.parse("content://sms/" + id), null, null); 
            } while (c.moveToNext()); 
        } 
    } catch (Exception e) { 

    } 
}
like image 68
Royston Pinto Avatar answered Mar 18 '26 20:03

Royston Pinto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!