0

我找到了一些话题,但他们没有帮助我解决我的问题。我想删除我的草稿短信。多次尝试使用此 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)

有人请告诉我我哪里做错了吗?

4

2 回答 2

2

试试这个:

Uri deleteUri = Uri.parse("content://sms");
getContentResolver().delete(deleteUri, "type=?", new String[] {String.valueOf(3)});
于 2013-09-08T18:32:23.843 回答
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());
    }
}

希望能帮助到你 :)

在它的重复之间:删除android中的草稿短信

但是确实测试并验证了它的工作原理。

于 2013-09-08T18:47:08.540 回答