can we get chrome browsing history/bookmarks in our android app

Krishna Bhatia picture Krishna Bhatia · Oct 30, 2012 · Viewed 16.5k times · Source

can we get chrome browsing history/bookmarks like we get in default browser using READ_HISTORY_BOOKMARKS permission? PS:I Just want to know is it possible?

Answer

Aditya picture Aditya · Jun 20, 2013

Yes it is very much possible. Use this uri: content://com.android.chrome.browser/bookmarks instead of Browser.BOOKMARKS_URI

String[] proj = new String[] { Browser.BookmarkColumns.TITLE,Browser.BookmarkColumns.URL };
Uri uriCustom = Uri.parse("content://com.android.chrome.browser/bookmarks");
String sel = Browser.BookmarkColumns.BOOKMARK + " = 0"; // 0 = history, 1 = bookmark
Cursor mCur = getContentResolver().query(uriCustom, proj, sel, null, null);
mCur.moveToFirst();
@SuppressWarnings("unused")
String title = "";
@SuppressWarnings("unused")
String url = "";

if (mCur.moveToFirst() && mCur.getCount() > 0) {
    boolean cont = true;
    while (mCur.isAfterLast() == false && cont) {
        title = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.TITLE));
        url = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.URL));
        // Do something with title and url
        mCur.moveToNext();
    }
}

Havent tested the code for errors but it should work fine. The important thing is knowing the uri to use. Reading this and this might help.