Clear Android Maps history programmatically

2019-08-01 02:16发布

问题:

I want to programmatically clear the history of the android maps (and navigation) application.

I know there is a way to clear the browser history via

Browser.clearSearches(getContentResolver());

and the corresponding permission: com.android.browser.permission.WRITE_HISTORY_BOOKMARKS and this works fine (2.2.).

I couldn't find any way to clear the Maps-History though. Clearing the google/history online doesn't help either.

There are some apps in the market that promote to do that, so there must be an API for it, but i really couldn't find it yet.

I also messed around a bit with CLEAR_APP_CACHE and CLEAR_APP_USER_DATA but seems like they are signed/root-only permissions and delte too much anyways.

回答1:

Got a reply from Richard, developer of aClean:

To clear Google-Maps-Recent-Search-Suggestions:

SearchRecentSuggestions mapsrs = new SearchRecentSuggestions(this.getBaseContext(), "com.google.android.maps.SearchHistoryProvider", 1);
mapsrs.clearHistory();

Still doesn't clear recent destination of Navigation, tried but there seems to be no equivalent..?

IMPORTANT NOTE:

Once you do mapsrs.clearHistory(); Afterwards when the Maps-Application gets force-stopped afterwards, your Application will be killed, too. Probably I'm missing to unregister/unsync the Provider. But I have abandoned to try to reset it now anyways.



回答2:

This sounds like something that you'd need SU permissions for.