How to remove call logs from android programmatically?
<uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
You need to give only this permission to work along with this method:
this.getContentResolver().delete(CallLog.Calls.CONTENT_URI, null, null);
Its working perfectly for me. I've tested it on my Moto-G running Kitkat 4.4.2 and Samsung Note with Jelly Bean 4.1.
Make sure u have following permissions in Manifest.xml
:
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
For deleting call logs for particular number try this way:
public void DeleteCallLogByNumber(String number) {
String queryString = "NUMBER=" + number;
this.getContentResolver().delete(CallLog.Calls.CONTENT_URI, queryString, null);
}
The existing solution will not delete numbers with 0 or + prefix. For this to work for all phone numbers, one needs to put the number in single quotes, like so:
String queryString = "NUMBER='"+numberToDelete+"'";
context.getContentResolver().delete(CallLog.Calls.CONTENT_URI, queryString, null);
Hope this helps.
Accepted answer will delete all calls from call log for a specific number. If you want to delete a only single call you can do it by passing CallLogId to that function and run this query.
public void DeleteCallById(String idd) {
this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,CallLog.Calls._ID + " = ? ",
new String[] { String.valueOf(idd) });
}