删除最后的短信

时间:2014-05-08 21:26:21

标签: android sms android-4.4-kitkat

使用此代码:

    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);
        }

    }

我可以删除最后一个(整个)对话,但是我想删除最后一次会话中的最后一个短信,而不是整个对话本身,哪个方法可以做到?

由于

1 个答案:

答案 0 :(得分:1)

解决了问题,

代码:

 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);

由于