5

How can you clear the entire call log history in android? Currently i have this code that can only clear a particular call log

public void DeleteCallLogByNumber(String number) {   
    String queryString="NUMBER="+number; 
    this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,queryString,null);
    }  
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
dythe
  • 840
  • 5
  • 21
  • 45
  • 1
    Not ideal so a comment not an answer but you could always read all call log entries and delete them in this way... – Basic Aug 02 '12 at 22:36
  • Try this? @Rpc(description = "Deletes an Entry from call Log ") public void deleteAnEntryFromCallLog(String number) { try { Uri CALLLOG_URI = Uri.parse("content://call_log/calls"); mService.getContentResolver().delete(CALLLOG_URI,CallLog.Calls.NUMBER +"=?",new String[]{number}); } catch(Exception e) { e.getMessage(); } } – Alexander Wigmore Aug 02 '12 at 22:37
  • @AlexanderWigmore that doesnt work – dythe Aug 02 '12 at 22:45
  • if you can delete one, then you can delete them all. just query the call log to get all the entries then delete them one by one. – Jeffrey Blattman Aug 02 '12 at 22:48

3 Answers3

7

I was able to do it with this, It's been a while though. Not sure if this still works.

getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI, null, null) ;

EDIT: Please note I am not certain that the platform designers intended for apps to be able to delete the call log See this dev blog post. So while this does technically work please take this as a fair warning that it may at any point change and break what you are trying to build.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
2

You cannot delete all with a single API call.

You can, however, delete them one-by-one (as mentioned in the comments) by looping through them all. To do that, you'll want to use a Cursor. Keep in mind: that link only wipes out calls of less than 60 seconds, so you'll have to modify the Cursor creation to delete all calls instead.

Also note: For APIs 11+, you should be using CursorLoader instead of managedQuery(...).

Cat
  • 66,919
  • 24
  • 133
  • 141
1

Try this:

String queryString="DURATION >= 0"; 
this.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI, queryString, null);
Yaqub Ahmad
  • 27,569
  • 23
  • 102
  • 149