Reputation: 21
Can any one please tell me how to delete call log from android phone,
I am using following line of code
getActivity().getContentResolver().delete(CallLog.Calls.CONTENT_URI, null, null);
but, this is not working for me I want to delete whole call log history.
Upvotes: 2
Views: 2812
Reputation: 5541
This code is working for me.I am deleting call log by its log id please check below code for it.
private void deleteCall(String idd) {
context.getContentResolver().delete(CallLog.Calls.CONTENT_URI, CallLog.Calls._ID + " = ? ",new String[]{String.valueOf(idd)});
}
Upvotes: 0
Reputation: 21
Yeah this is working perfectly for me in android Lollipop :)
private void deleteCall(String number) {
Uri CALLLOG_URI = Uri.parse("content://call_log/calls");
getActivity().getContentResolver().delete(CALLLOG_URI, CallLog.Calls.NUMBER +"=?",new String[]{number});
Toast.makeText(getActivity(), "Call Log Deleted", Toast.LENGTH_SHORT).show();
}
Upvotes: 0
Reputation: 365
Following code work for me..
private void deleteNumber() {
try {
String strNumberOne[] = { "00577698160" };
Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, CallLog.Calls.NUMBER + " = ? ", strNumberOne, "");
boolean bol = cursor.moveToFirst();
if (bol) {
do {
int idOfRowToDelete = cursor.getInt(cursor.getColumnIndex(CallLog.Calls._ID));
getContentResolver().delete(Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, String.valueOf(idOfRowToDelete)), "", null);
} while (cursor.moveToNext());
}
} catch (Exception ex) {
System.out.print("Exception here ");
}
}
Edit: following code is also work for me In API 23
make sure u have following permission in manifast.xml:
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
for Deleting Calllogs for particular number try this way:
public void DeleteCallLogByNumber(String number) {
String queryString="NUMBER="+number;
this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,queryString,null);
}
}
Upvotes: 4