Clear Chrome Browser History in Android Programmatically |Android App Development With AndroidCource

Saturday 7 July 2018

Clear Chrome Browser History in Android Programmatically

How to clear chrome browser history in android programmatically.to delete browser history in android.In this example of built - in chrome history to delete/clear in your application through when click your application button and clear history in chrome you want to searches history.


Use This Method


private void clearHistoryChrome() {

        ContentResolver contentResolver = getContentResolver();

        if (canClearHistory(contentResolver)){
            deleteHistory(contentResolver,null);
        }

    }


private void deleteHistory(ContentResolver cr, String whereClause) {
        String CONTENT_URI = "content://com.android.chrome.browser/history";
        String CONTENT_URI1 = "file:///com.android.chrome.browser/history";

        Uri URI = Uri.parse(CONTENT_URI);
        Cursor cursor = null;
        try {
            cursor = cr.query(URI, new String[]{"url"}, whereClause,
                    null, null);
            if (cursor != null) {
                if (cursor.moveToFirst()) {
                    final WebIconDatabase iconDb = WebIconDatabase.getInstance();
                    do {
                        // Delete favicons
                        // TODO don't release if the URL is bookmarked
                        iconDb.releaseIconForPageUrl(cursor.getString(0));
                    } while (cursor.moveToNext());
                    cr.delete(URI, whereClause, null);
                }
            }
        } catch (IllegalStateException e) {
            Log.i("DEBUG_", "deleteHistoryWhere IllegalStateException: " + e.getMessage());
            return;
        } finally {
            if (cursor != null) cursor.close();
        }

        Log.i("DEBUG_", "deleteHistoryWhere: GOOD");
    }


0 comments:

Post a Comment