2

I'd like to write a small android widget to getting bookmarks from my firefox browser, but my code:

Cursor myCursor=Browser.getAllBookmarks(main.getContentResolver());

not working. This cursor is always empty. It is very strange, because all my browsers (firefox, chrome) have a lot of bookmarks.

I have found this code:

String query = Browser.BookmarkColumns.BOOKMARK+"=1";
Cursor crs=main.getContentResolver().query( UriProvider.QUERY
                , columns
                , query
                , null
                , sortOrder
        );

but efect is the same, result is empty.

I have problem with understanding nature of android.provider.Browser class. Is it a interface to database table ? What kind of data I can find in this table (bookmarks from firefox, or chrome, or both ???). When this table is synchronized with ff/chrome ?

Thanks for any suggestions...

Best regards mario

mwwojcik
  • 31
  • 1
  • 6

2 Answers2

3
String[] proj = new String[] { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL };
    String sel = Browser.BookmarkColumns.BOOKMARK + " = 0"; // 0 = history, 1 =bookmark
    mCur = this.managedQuery(Browser.BOOKMARKS_URI, proj, sel, null, null);
    this.startManagingCursor(mCur);
    mCur.moveToFirst();

    String title = "";
    String url = "";

    if (mCur.moveToFirst() && mCur.getCount() > 0) {
        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();
        }
    }

have you added permission in AndroidManifest.xml
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>

iluvatar_GR
  • 1,017
  • 13
  • 19
Nitin Misra
  • 4,472
  • 3
  • 34
  • 52
  • @Nitin Misra In Android M use of that permission is deprecated, any alternative solution for that? – keshav kowshik Aug 11 '15 at 05:47
  • @Keshav1234 Still working on it, here's a thread. let me know if you are able to crack this problem: http://stackoverflow.com/questions/33486463/how-to-get-chrome-history-bookmarks-in-android-marshmallow-api-23/33486978#33486978 – user1406716 Nov 02 '15 at 22:07
1

Thank you for reply.

Your code works but only for default build-in browser.

For chrome I have to use special content provider uri:

Uri uriCustom = Uri.parse("content://com.android.chrome.browser/bookmarks");

For FF the thing is more complicated, because when I try use uri:

Uri uriCustom = Uri.parse("content://org.mozilla.firefox.db.browser/bookmarks");

I get :

java.lang.SecurityException: Permission Denial: reading org.mozilla.firefox.db.BrowserProvider uri content://org.mozilla.firefox.db.browser/bookmarks from pid=xxxx, uid=xxxx requires org.mozilla.firefox.permissions.BROWSER_PROVIDER, or grantUriPermission()
StarsSky
  • 6,721
  • 6
  • 38
  • 63
mwwojcik
  • 31
  • 1
  • 6