简体   繁体   中英

How to Delete Call Log

Can any one please tell me how to delete call log from android phone,

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

make sure u have following permission in 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:

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 :)

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.

private void deleteCall(String idd) {

    context.getContentResolver().delete(CallLog.Calls.CONTENT_URI, CallLog.Calls._ID + " = ? ",new String[]{String.valueOf(idd)});

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM