Here we are going to explain how we can delete all phone call logs programmatically
Include the READ_CALL_LOG and WRITE_CALL_LOG permissions in your manifest file,
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
Here is the function to delete all the phone calls, specify a TYPE for the calls so that it gets removed,
private void deletePhoneCallLogs() {
Cursor cursor = getContext().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(CallLog.Calls._ID));
Uri deleteUri = ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, id);
Log.d("PhoneCall","My delete PhoneCall"+deleteUri);
getContext().getContentResolver().delete(CallLog.Calls.CONTENT_URI , "type="+CallLog.Calls.TYPE , null); }
cursor.close();
}
Here is the type of the call (incoming, outgoing or missed).
INCOMING_TYPE
OUTGOING_TYPE
MISSED_TYPE
VOICEMAIL_TYPE
REJECTED_TYPE
BLOCKED_TYPE
ANSWERED_EXTERNALLY_TYPE
For delete the missed calls here is the code,
getContentResolver().delete(CallLog.CONTENT_URI , "type="+CallLog.Calls.MISSED_TYPE , null);
You can get more information about Call Types from here https://developer.android.com/reference/android/provider/CallLog.Calls#TYPE