Delete particular log from call log

2019-09-21 04:10发布

问题:

I want to delete a particular entry from call log only once..

getActivity().getContentResolver().delete(calluri, queryString, null);

The above code delete all the entries from call log

回答1:

try do delete call log by call id. use below code

int res = Call_logs.this.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI,"_ID = "+ calls_id_list.get(i),null);
        if (res == 1) {
            // Log delete

        } else {
            // Log not Delete

        }

to delete all call log:

Uri uri = Uri.parse("content://call_log/calls");

int d  = getContentResolver().delete(uri, null, null);


回答2:

STEP 1: Make sure that you have following permission in manifast.xml:

<uses-permission android:name="android.permission.READ_CONTACTS" /> 
<uses-permission android:name="android.permission.WRITE_CONTACTS" />

STEP 2: And for deleting Call logs for particular number:

public void deleteCallLogByPhoneNumber(String number) {   

    String queryString="NUMBER="+number; 
    this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,queryString,null);

}