Programmatically search Chrome browser history

I am making a small Java application to show which URLs in Chrome the user visited the most. How to access my browser history in Java?

+3
source share
1 answer

Create a class ContentObserver...

static class ChromeOberver extends ContentObserver {   
    public ChromeOberver(Handler handler) { 
        super(handler);          
    } 

    @Override
    public void onChange(boolean selfChange) { 
        onChange(selfChange, null); 
    }    

    @Override
    public void onChange(boolean selfChange, Uri uri) {
        super.onChange(selfChange);
        Log.d(TAG, "onChange: " + selfChange);

        Cursor cursor = context.getContentResolver()
              .query(CHROME_BOOKMARKS_URI, new String() {"title", "url"}, 
                                           "bookmark = 0", null, null);

        // process cursor results
    }
}

and register this class to track changes in the history / bookmark:

private static String CHROME_BOOKMARKS_URI = 
       "content://com.android.chrome.browser/bookmarks";

ChromeOberver observer = new ChromeOberver();
resolver.registerContentObserver(CHROME_BOOKMARKS_URI, true, observer);

Do not forget the permission:

<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
+5
source

Source: https://habr.com/ru/post/1543852/


All Articles