在安卓手机中删除特定号码的通话记录

3
我正在尝试删除特定号码的所有通话记录。
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 ");
}

我想执行一个LIKE查询,因为在通话记录中保存的mobNum是+916666666666,而我正在传递号码6666666666,所以它们不匹配。有人可以帮我解决这个问题吗?

2个回答

3
尝试使用以下代码从历史记录中删除任何特定数字。
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});

您可以通过以下方式按用户名删除通话记录
context.getContentResolver().delete(CALLLOG_URI,CallLog.Calls.CACHED_NAME +"=?",new String[]{name});

1

@umesh,你可以分享答案吗? - Chanaka udaya
第二个链接现在无法使用。有人可以分享如何解决吗? - Jun

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接