Delete call log in android for particular number

天大地大妈咪最大 提交于 2019-12-17 16:41:23

问题


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?


回答1:


Check the following links:

  • Call log deletion in Android
  • SO: Delete call from call log after call end



回答2:


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});


来源:https://stackoverflow.com/questions/14019684/delete-call-log-in-android-for-particular-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!