Like the title. I want to delete cookie, cache of browser of Android by coding in my application. (browser not webview) Thank you!
Asked
Active
Viewed 5,548 times
2 Answers
6
In your Activity
or Service
, add
ContentResolver cR = getContentResolver();
if(Browser.canClearHistory(cR)){
Browser.clearHistory(cR);
Browser.clearSearches(cR);
}
where Browser
is the android.provider.Browser
class.
This will clear the default browser's history.

Yash Sampat
- 30,051
- 12
- 94
- 120
-
3cannot resolver the method clearHistory (android.content.contentresolver) – DKV Mar 02 '16 at 13:13
-
what is your device's API level ? – Yash Sampat Mar 02 '16 at 13:26
-
I cleared the cookies. that solved my bug. thank you for your response. – DKV Mar 07 '16 at 08:06
-
I cant find these api in Android 10. It is too old – JeckOnly May 05 '23 at 08:51
0
Yes it is possible to clear chrome history & searches from your application. Please see below.
/**
* Clear the browser history
*/
private void clearChromeHistory(){
ContentResolver cr = getContentResolver();
Uri historyUri = Uri.parse("content://com.android.chrome.browser/history");
Uri searchesUri = Uri.parse("content://com.android.chrome.browser/searches");
deleteChromeHistoryJava(cr, historyUri, null, null);
deleteChromeHistoryJava(cr, searchesUri, null, null);
}
/**
* Delete chrome browser hisory
* @param cr content resolver
* @param whereClause Uri of the browser history query
* @param projection projection array
* @param selection selection item
*/
private void deleteChromeHistoryJava(ContentResolver cr, Uri whereClause, String[] projection, String selection) {
Cursor mCursor = null;
try {
mCursor = cr.query(whereClause, projection, selection,
null, null);
Log.i("deleteChromeHistoryJava", " Query: " + whereClause);
if (mCursor != null) {
mCursor.moveToFirst();
int count = mCursor.getColumnCount();
String COUNT = String.valueOf(count);
Log.i("deleteChromeHistoryJava", " mCursor count" + COUNT);
String url = "";
if (mCursor.moveToFirst() && mCursor.getCount() > 0) {
while (!mCursor.isAfterLast()) {
url = mCursor.getString(mCursor.getColumnIndex(Browser.BookmarkColumns.URL));
Log.i("deleteChromeHistoryJava", " url: " + url);
mCursor.moveToNext();
}
}
cr.delete(whereClause, selection, null);
Log.i("deleteChromeHistoryJava", " GOOD");
}
} catch (IllegalStateException e) {
Log.i("deleteChromeHistoryJava", " IllegalStateException: " + e.getMessage());
} finally {
if (mCursor != null) mCursor.close();
}
}
Add permissions in manifest
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>
I have no idea if we can delete the cache/cookies using this, but i will post if i can get any further information.

Dheeraj T
- 1
- 2