3

How to get default browser bookmarks, and how to store default browser bookmarks to text files.

In this links to i got the Bookmarks URL and Label (Include all sub-folders URL and Label). Refer this link Get browser history and search result in android

How to get a Bookmarks URL and Label in the tree structure format.

  1. Default Browser contains URL.
  2. In this BOOKMARKS contains URL and Folders and Sub-Folders.
  3. Each Folder contains some URL and Folders
  4. How do i get the tree structure format.

For Example, How do get this tree structure format

BOOKMARKS (Parent Folder)
    JAVA (Child Folder)
        http://www.java2s.com/
        http://roseindia.net/
    ANDROID (Child Folder)
        ANDROIDDEVELOPER (Child Folder)
            http://developer.android.com/index.html
        https://play.google.com/store?hl=en
    http://developer.android.com

How do get tree structure format. Is it possible. Please Guide me.

Thanks in advance.

Community
  • 1
  • 1
Sathish Sathish
  • 2,251
  • 3
  • 20
  • 21

2 Answers2

12

Add the below to your Android Manifest file as mentioned

<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
Skillachie
  • 3,176
  • 1
  • 25
  • 26
1

You can get bookmarks with following code snippet -

static final String[] columns = { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL };
Cursor query = getContentResolver().query(Browser.BOOKMARKS_URI,columns, null, null, null);
query.moveToFirst();
while (query.moveToNext()) {
    String title = query.getString(query.getColumnIndex(Browser.BookmarkColumns.TITLE));
    String url = query.getString(query.getColumnIndex(Browser.BookmarkColumns.URL));
}

Also you will need to give following permission in the manifest file to read them -

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

For more detail see documentation

public static final Uri BOOKMARKS_URI

A table containing both bookmarks and history items. The columns of the table are defined in Browser.BookmarkColumns. Reading this table requires the READ_HISTORY_BOOKMARKS permission and writing to it requires the WRITE_HISTORY_BOOKMARKS permission.

Community
  • 1
  • 1
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • Code gets history too. Some code for get ONLY the BOOKMARKS? –  May 03 '15 at 22:58
  • Where is the documentation of this permission? The link leads to the Browser class; there is nothing about permissions or bookmarks there... – pkalinow Sep 13 '17 at 13:19