How to clear history of chrome browser. For native browser i use following code -
Browser.clearHistory(getContentResolver());
But this does not work for chrome. How can i clear chrome browser history? Is it possible?
How to clear history of chrome browser. For native browser i use following code -
Browser.clearHistory(getContentResolver());
But this does not work for chrome. How can i clear chrome browser history? Is it possible?
It work fo me
Uri BOOKMARKS_URI = Uri.parse("content://browser/bookmarks");
String TITLE = "title";
String VISITS = "visits";
String BOOKMARK = "bookmark";
ContentResolver resolver = getContentResolver();
try {
Log.i("DEBUG_", "ContentResolver");
Cursor c = resolver.query(
BOOKMARKS_URI,
null,
null, null, null);
c.moveToFirst();
Log.i("DEBUG_", "Cursor : " + c.toString());
resolver.delete(BOOKMARKS_URI, "bookmark == 1", null);
Log.i("DEBUG_", "ContentResolver delete ");
} catch (IllegalStateException e) {
Log.i("DEBUG_", "IllegalStateException " + e.getMessage());
e.printStackTrace();
}
or
Cursor faves = managedQuery(BOOKMARKS_URI,
requestedColumns,
null, null, null);
Yes it is posssible to clear chrome history 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");
deleteChromeHistoryJava(cr, historyUri, 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 permission in manifest
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>