【问题标题】:How to delete all sms from inbox programmatically in android?如何在android中以编程方式从收件箱中删除所有短信?
【发布时间】:2012-03-15 15:32:03
【问题描述】:

我正在开发一个应用程序,我想在其中删除收件箱中的所有 SMS。 为此,我使用了以下代码。

Uri uriSms = Uri.parse("content://sms/inbox");
Cursor c = getContentResolver().query(uriSms, null,null,null,null); 
int id = c.getInt(0);
int thread_id = c.getInt(1); //get the thread_id
getContentResolver().delete(Uri.parse("content://sms/conversations/" + thread_id),null,null);

此代码不起作用。 有没有办法做同样的事情?

【问题讨论】:

标签: android


【解决方案1】:

删除的uri是"content://sms/" + id;

Uri inboxUri = Uri.parse("content://sms/inbox");
int count = 0;
Cursor c = context.getContentResolver().query(inboxUri , null, null, null, null);
while (c.moveToNext()) {
    try {
        // Delete the SMS
        String pid = c.getString(0); // Get id;
        String uri = "content://sms/" + pid;
        count = context.getContentResolver().delete(Uri.parse(uri),
                null, null);
    } catch (Exception e) {
    }
}
return count;

【讨论】:

  • 这是针对单个消息还是转换?
  • 这也会删除所有彩信吗?
  • 这将是收件箱中的所有短信
【解决方案2】:
//delete all call logs
Uri callLog = Uri.parse("content://call_log/calls");
int rs1 = getContentResolver().delete(callLog, null, null);

//delete all sms
Uri inboxUri = Uri.parse("content://sms/");       
int rs2 = getContentResolver().delete(inboxUri, Sms._ID + "!=?", new String[]{"0"});

【讨论】:

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