[英]How to Delete Call Log
Can any one please tell me how to delete call log from android phone, 任何人都可以告诉我如何从Android手机删除通话记录,
I am using following line of code 我正在使用以下代码行
getActivity().getContentResolver().delete(CallLog.Calls.CONTENT_URI, null, null);
but, this is not working for me I want to delete whole call log history. 但是,这对我不起作用我想删除整个通话记录历史记录。
Following code work for me.. 以下代码为我工作..
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 ");
}
}
Edit: following code is also work for me In API 23 编辑:以下代码也适用于我在API 23中
make sure u have following permission in manifast.xml: 确保你在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" />
for Deleting Calllogs for particular number try this way: 删除特定数字的Calllogs尝试这种方式:
public void DeleteCallLogByNumber(String number) {
String queryString="NUMBER="+number;
this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,queryString,null);
}
}
Yeah this is working perfectly for me in android Lollipop :) 是的,这在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();
}
This code is working for me.I am deleting call log by its log id please check below code for it. 这段代码对我有用。我正在通过其日志ID删除通话记录,请检查下面的代码。
private void deleteCall(String idd) {
context.getContentResolver().delete(CallLog.Calls.CONTENT_URI, CallLog.Calls._ID + " = ? ",new String[]{String.valueOf(idd)});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.