Reputation: 448
I found some topic but they were not helped me to solve my problem. I want to delete my draft sms. Have tried with this uri so many time:
contentResolver.delete("content://sms/draft", " ", null); //this is line 173
It throws this exeption:
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)
Anybody please tell me where did I wrong?
Upvotes: 0
Views: 623
Reputation: 539
did just make a sample project and tested it..
Add to your Manifest :
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
And try the code from 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());
}
}
Hope it helps :)
Between its a duplicate from : Delete draft SMS in android
But did test and verify it working.
Upvotes: 0
Reputation: 1250
Try this one:
Uri deleteUri = Uri.parse("content://sms");
getContentResolver().delete(deleteUri, "type=?", new String[] {String.valueOf(3)});
Upvotes: 2