In our application there is a feature delete SMS programmatically. The application Target SDK version is 26 . And i have changed default SMS application as default SMS app which is available on device. I have tried the code below.
Requirement: Need code for delete all sms and MMS
First one:
public boolean deleteSms() {
Cursor c = getApplicationContext().getContentResolver().query(Uri.parse("content://sms/"), 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);
this.getContentResolver().delete(
Uri.parse("content://sms/" + id), null, null);
isSmsDeleted = true;
}
} catch (Exception ex) {
isSmsDeleted = false;
}
return isSmsDeleted;
}
and I have tried another one function that is
private int deleteSms() {
try {
ContentResolver localContentResolver = context.getContentResolver();
Uri localUri = Uri.parse("content://sms");
return localContentResolver.delete(localUri, null, null);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
return 0;
}
My Manifest Permission is
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
When i debug the above code the return localContentResolver.delete(localUri, null, null);
it returns 0. And both functionality is not working
Tested Device : Google Pixel 2Xl version 8.1 and MIUI Redmi 5 version 7.1.2