How do you clear your call logs history in android?

一世执手 提交于 2020-01-01 10:58:24

问题


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

回答1:


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.




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




回答3:


Try this:

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


来源:https://stackoverflow.com/questions/11786800/how-do-you-clear-your-call-logs-history-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!