从草稿框中删除短信

时间:2013-09-08 17:47:23

标签: android sms

我找到了一些话题,但他们没有帮助我解决我的问题。我想删除我的草稿短信。已经尝试了这么多次uri:

  contentResolver.delete("content://sms/draft", " ", null); //this is line 173

它抛出了这个例子:

 09-09 00:43:43.454: E/AndroidRuntime(2933): Caused by: java.lang.IllegalArgumentException: Unknown URL
 09-09 00:43:43.454: E/AndroidRuntime(2933):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java)
 09-09 00:43:43.454: E/AndroidRuntime(2933):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java)
 09-09 00:43:43.454: E/AndroidRuntime(2933):    at android.content.ContentProviderProxy.delete(ContentProviderNative.java)
 09-09 00:43:43.454: E/AndroidRuntime(2933):    at android.content.ContentResolver.delete(ContentResolver.java)
 09-09 00:43:43.454: E/AndroidRuntime(2933):    at com.haanz.smsbackup.SmsProvider.query(SmsProvider.java:173)
 09-09 00:43:43.454: E/AndroidRuntime(2933):    at android.content.ContentProvider.query(ContentProvider.java)
 09-09 00:43:43.454: E/AndroidRuntime(2933):    at android.content.ContentProvider$Transport.query(ContentProvider.java)
 09-09 00:43:43.454: E/AndroidRuntime(2933):    at android.content.ContentResolver.query(ContentResolver.java)
 09-09 00:43:43.454: E/AndroidRuntime(2933):    at android.content.ContentResolver.query(ContentResolver.java)

有人请告诉我哪里错了?

2 个答案:

答案 0 :(得分:2)

试试这个:

Uri deleteUri = Uri.parse("content://sms");
getContentResolver().delete(deleteUri, "type=?", new String[] {String.valueOf(3)});

答案 1 :(得分:0)

刚做了一个示例项目并对其进行了测试..

添加到您的清单:

<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>

尝试SO

中的代码
private void deleteDrafts() {
    /*
     * This will delete all drafts from Messaging App.
     */
    try {
        Uri uriSms = Uri.parse("content://sms/draft");
        Cursor c = getContentResolver().query(uriSms,
                new String[] { "_id", }, null, null, null);

        if (c != null && c.moveToFirst()) {
            do {
                long id = c.getLong(0);
                Log.d("Delete Draft ID", "" + id);
                getContentResolver().delete(
                        Uri.parse("content://sms/" + id), null, null);
            } while (c.moveToNext());
        }
    } catch (Exception e) {
        Log.d("error", "" + e.getMessage());
    }
}

希望有所帮助:)

来自:Delete draft SMS in android

的副本

但确实测试并确认它有效。