Question

Using this code:

    Uri uriSMSURI = Uri.parse("content://sms");
    Cursor cur = mContext.getContentResolver().query(uriSMSURI, null, null, null,null);
    String phoneNo, msg;
    if (cur.moveToFirst()) {
        String pid = cur.getString(1);
        // do some process
        Toast.makeText(mContext, pid, Toast.LENGTH_LONG).show();
        Cursor cur2 = mContext.getContentResolver().query(Uri.parse("content://sms/conversations/" + pid), null, null, null,null);
        if(cur2.moveToFirst()){
            ////Tried with this with no luck, its Delete the whole Conversation :
            String pid2 = cur2.getString(1);
            String uri = "content://sms/conversations/" + pid2;
            mContext.getContentResolver().delete(Uri.parse(uri), null, null);
        }
    
    }

I am able to Delete the last(whole) Conversation, but I am looking to delete the Last SMS in the last conversation only, not the whole conversation itself, which way to do it?

Was it helpful?

Solution

Problem Solved,

Code :

 Uri uriSMSURI = Uri.parse("content://sms/");
 Cursor cur = mContext.getContentResolver().query(uriSMSURI, null, null, null, null);
 if (cur.moveToFirst()) {
////Changed to 0 to get Message id instead of Thread id : 
 String MsgId= cur.getString(0);



 mContext.getContentResolver().delete(Uri.parse("content://sms/" + MsgId), null, null);

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top