Reputation: 1168
I am trying to delete all call logs of particular number.
try {
String strNumberOne[] = {number};
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 ");
}
I want to fire a LIKE
query, because the mobNum saved in callLog is +916666666666 and i am passing number 6666666666. so its not matching. can anybody help me to overcome this issue?
Upvotes: 3
Views: 6189
Reputation: 59946
Try this code to delete any particular number from history
String number="4666";//any number
Uri CALLLOG_URI = Uri.parse("content://call_log/calls");
context.getContentResolver().delete(CALLLOG_URI,CallLog.Calls.NUMBER +"=?",new String[]{number});
you can also delete call log by user name by doing this
context.getContentResolver().delete(CALLLOG_URI,CallLog.Calls.CACHED_NAME +"=?",new String[]{name});
Upvotes: 3