首页 > 代码库 > android获取系统自带浏览器书签

android获取系统自带浏览器书签

    刚刚接手一个备份系统浏览器书签的模块,现在把代码贴出来,另外有几点疑问请路过的大神指教

1、根据官方api应该是有以下几个字段是可以获取的


  但是除了TITLE和URL能获取其他的都会报java.lang.IllegalStateException: Couldn‘t read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.异常

   2、是不是只能获得系统自带浏览器书签?如果我装的是百度或其他浏览器建的书签是不是就得不到了?

以下是我的代码片段

// 按访问时间排序  
        String orderBy = Browser.BookmarkColumns.VISITS + " DESC";  
        // flag=1表示书签  
        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();  
            // TODO 可能为空的字段  
//          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();  


android获取系统自带浏览器书签