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?
can we get chrome browsing history/bookmarks in our android app
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. –
Weiman
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.
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)? –
Churchwarden
This will not work in Marshmallow anymore: developer.android.com/about/versions/marshmallow/… –
Danieu
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. –
Revelation
© 2022 - 2024 — McMap. All rights reserved.