12

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?

Aditya
  • 5,101
  • 4
  • 27
  • 50
Krishna Bhatia
  • 195
  • 1
  • 2
  • 9
  • 2
    I think the answer is no. I'm talking about the normal case i.e. without root access, each app has individual data that kept within /data folder and have no access permission to other app's folder. However if you have root access, thats another case. – dumbfingers Oct 30 '12 at 11:32

1 Answers1

14

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.

Aditya
  • 5,101
  • 4
  • 27
  • 50
  • 3
    How to figure out WHICH URI is the good one for Bookmarks (Which one must be used)? I use Browser.BOOKMARKS_URI (= Uri.parse("content://browser/bookmarks")): works fine on most devices, but, on some devices, (probably using Chrome as default), it triggers a "java.lang.IllegalArgumentException: Unknown URL content://browser/bookmarks" Should I try Chrome URI in this case? "content://com.android.chrome.browser/bookmarks" What is the proper way to know which bookmark URI is the (good) one to use on (a given device/configuration)? – Pascal Jan 15 '15 at 05:19
  • 7
    This will not work in Marshmallow anymore: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-bookmark-browser – user1406716 Oct 25 '15 at 21:32
  • 2
    is it possible to run this code only if the device's version is less then Marshmallow?. Because it seems the BookmarkColumns is removed from the framework. – Jayavinoth Jun 11 '18 at 10:01