Android acquisition system built-in browser bookmarks

Source: Internet
Author: User

Android acquisition system built-in browser bookmarks

I have just taken over a browser bookmarks module of the backup system and now I am posting the code. I have some questions. Please kindly advise me. 

1. According to the official api, the following fields can be obtained:

However, if the TITLE and URL can be obtained, java is reported. lang. illegalStateException: Couldn "t read row 0, col-1 from CursorWindow. make sure the Cursor is initialized correctly before accessing data from it. exception

2. Is it possible to only obtain bookmarks from built-in browsers of the system? If I installed bookmarks created by Baidu or other browsers, wouldn't they be lost?

The following is my code snippet


// Sort by access time String orderBy = Browser. bookmarkColumns. VISITS + "DESC"; // flag = 1 indicates the String whereClause = Browser. bookmarkColumns. BOOKMARK + "= 1"; ContentResolver cr = context. getContentResolver (); Cursor cursor = cr. query (Browser. BOOKMARKS_URI, Browser. HISTORY_PROJECTION, whereClause, null, orderBy); while (cursor! = Null & cursor. moveToNext () {BookMark bookMark = new BookMark (); // a field that TODO may be empty // String id = cursor. getString (cursor //. getColumnIndex (Browser. bookmarkColumns. _ ID); // if (id! = Null) // bookMark. set_id (id); // String count = cursor. getString (cursor //. getColumnIndex (Browser. bookmarkColumns. _ COUNT); // if (count! = Null) // bookMark. set_count (count); String title = cursor. getString (cursor. getColumnIndex (Browser. BookmarkColumns. TITLE); if (title! = Null) bookMark. setTitle (title); String url = cursor. getString (cursor. getColumnIndex (Browser. BookmarkColumns. URL); if (url! = Null) bookMark. setUrl (url); byte [] B = cursor. getBlob (cursor. getColumnIndex (Browser. BookmarkColumns. FAVICON); if (B! = Null) {bookMark. setFavicon (BitmapFactory. decodeByteArray (B, 0, B. length);} else {bookMark. setFavicon (null);} // bookMark. setCreated (cursor. getString (cursor //. getColumnIndex (Browser. bookmarkColumns. CREATED); // bookMark. setDate (cursor. getString (cursor //. getColumnIndex (Browser. bookmarkColumns. DATE); // bookMark. setVisits (cursor. getString (cursor //. getColumnIndex (Browser. bookmarkColumns. VISITS); // bookMarks. add (bookMark); bookMarks. add (bookMark);} cursor. close (); JSONObject jso = listTojsoJsonObject (bookMarks); return jso. toString ();


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.