【问题标题】:Deleting SMS in inbox删除收件箱中的短信
【发布时间】:2014-07-02 05:09:26
【问题描述】:

我们如何从收件箱中删除一条短信,我尝试了下面的代码,但它仍然全部删除。

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

【问题讨论】:

  • 看看你的 if 条件,你匹配的地址和你从光标处得到的地址是一样的。
  • 那怎么办只能删除一条短信。

标签: android sms message


【解决方案1】:

@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){
}

【讨论】:

    猜你喜欢
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    相关资源
    最近更新 更多