dythe
dythe

Reputation: 841

How do you clear your call logs history in android?

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);
    }  
}

Upvotes: 5

Views: 4447

Answers (3)

FoamyGuy
FoamyGuy

Reputation: 46856

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.

Upvotes: 7

Yaqub Ahmad
Yaqub Ahmad

Reputation: 27659

Try this:

String queryString="DURATION >= 0"; 
this.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI, queryString, null);

Upvotes: 1

Cat
Cat

Reputation: 67502

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(...).

Upvotes: 2

Related Questions