任何人都可以告诉我如何从Android手机中删除通话记录,
我正在使用以下代码行
getActivity().getContentResolver().delete(CallLog.Calls.CONTENT_URI, null, null);
但是,这对我不起作用我想删除整个通话记录历史记录。
答案 0 :(得分:4)
以下代码为我工作..
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 ");
}
}
编辑: 以下代码对我来说也适用于API 23
确保你在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" />
删除特定号码的Calllogs尝试这种方式:
public void DeleteCallLogByNumber(String number) {
String queryString="NUMBER="+number;
this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,queryString,null);
}
}
答案 1 :(得分:0)
是的,这对我在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();
}
答案 2 :(得分:0)
此代码对我有用。我正在通过其日志ID删除通话记录,请检查以下代码。
private void deleteCall(String idd) {
context.getContentResolver().delete(CallLog.Calls.CONTENT_URI, CallLog.Calls._ID + " = ? ",new String[]{String.valueOf(idd)});
}