Search code examples
androidfilterbookmarksandroid-contentresolver

Android Query for Bookmarks not filtering in Jelly Bean


Looking for some help regarding querying in different verions of Android. I have the following code that returns a cursor of bookmarks. I am trying to filter the browser to return only urls that are actual bookmarks, not just browser history. It works on version 3.1 but on my new Nexus 7, it will not filter by bookmark, but instead returns all browser history in the cursor. Any insight is much appreciated. I think I have run into issues with filtering and content resolver query's not paying attention to selection parameters but can't seem to find any info. Thanks.

String[]   mColumnStrings = 
{ 
  Browser.BookmarkColumns.TITLE, 
  Browser.BookmarkColumns.URL, 
  Browser.BookmarkColumns._ID,
  Browser.BookmarkColumns.BOOKMARK

 }; 

 try{
   bookmarksCursor =   getActivity().getContentResolver().query(Browser.BOOKMARKS_URI, mColumnStrings, Browser.BookmarkColumns.BOOKMARK+ " = 1 ", null , Browser.BookmarkColumns.URL + " ASC"); 
   getActivity().startManagingCursor(bookmarksCursor);


    return bookmarksCursor;

Solution

  • Its working fine for me...I tested it on AVD...actually Android 4.1 already have some default bookmarks...print the Browser.BookmarkColumns.BOOKMARK as well to verify weather the results are bookmarked or not...

    You can use this method specifically for your to varify...

    private void varify(Cursor bookmarksCursor) {
      bookmarksCursor.moveToFirst();
      while(bookmarksCursor.moveToNext()) {
        Log.v("title", bookmarksCursor.getString(0));
        Log.v("url", bookmarksCursor.getString(1));
        Log.v("id", bookmarksCursor.getString(2));
        Log.v("bookmark", bookmarksCursor.getString(3));
      }
    }
    

    Hope this works...

    If you decide that this answers your question, please mark it as "accepted". This will raise both your and my reputation score.