3

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
umesh
  • 1,148
  • 1
  • 12
  • 25

2 Answers2

3

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});
Pang
  • 9,564
  • 146
  • 81
  • 122
Adiii
  • 54,482
  • 7
  • 145
  • 148
1

Check the following links:

Andy
  • 49,085
  • 60
  • 166
  • 233
ridoy
  • 6,274
  • 2
  • 29
  • 60
  • 1
    Please see [Are answers that just contain links elsewhere really “good answers”?](http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers) – Arjan Dec 26 '12 at 08:10
  • @umesh, can you share the answer? – Chanaka udaya Jun 21 '13 at 12:49
  • The second link is not working now. Can someone please share how it could be done? – Jun Jul 16 '14 at 07:46