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 ();