在收件箱中删除短信

时间:2014-07-02 05:09:27

标签: android sms message

我们如何从收件箱中删除单个短信,我已尝试过下面的代码,但它仍然会删除所有内容。

Cursor c = getApplicationContext().getContentResolver().
query(Uri.parse("content://sms/sent"), new String[] { "_id", "thread_id", "address", "person","date", "body" }, null, null, null);
try {
while (c.moveToNext()) {
int id = c.getInt(0);
String address = c.getString(2);
if(address.equals(address)){
getApplicationContext().getContentResolver().delete(Uri.parse("content://sms/" + id),null, null);} 
}
}catch(Exception e){
 }

1 个答案:

答案 0 :(得分:0)

@ user3739864试试这个;

try {
    while (c.moveToNext()) {
    int id = c.getInt(0);
    String address = c.getString(2);

    if(id == // the id you want to delete ){
        getApplicationContext().getContentResolver().delete(Uri.parse("content://sms/" +             id),null, null);} 
    }

} catch(Exception e){
}