0

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;
Jaz
  • 371
  • 1
  • 6
  • 20

1 Answers1

0

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.

umair.ali
  • 2,714
  • 2
  • 20
  • 30
  • Thanks for testing. I will try it on an emulator as well. – Jaz Aug 16 '12 at 01:59
  • Interesting, on my Nexus 7 the log also shows all browsing history, not just bookmarks. However, running on the 4.1 emulator the log correctly shows only bookmarks. So my new Nexus 7 running 4.1.1 doesn't like the content resolver's query??? – Jaz Aug 16 '12 at 22:28
  • Hmmm...interesting...try one thing...use 'Browser.BookmarkColumns.BOOKMARK+ " = ?", new String[] {"1"}' in your argument list of query method. – umair.ali Aug 17 '12 at 07:17
  • 1
    Thanks for the suggestion but no luck. I had tried various combinations of selection and selectionArgs parameters hoping to trigger the query but nothing has worked yet. I found the following link, looks like some changes were made in 4.1.1 but not sure if the issue is linked. http://code.google.com/p/android/issues/detail?id=35610&q=4.1.1%20contentresolver&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars. Thanks again. – Jaz Aug 17 '12 at 20:42
  • Sorry I discovered my device was actually synced with my Chrome favorites from my pc. Weird, I guess Jelly Bean does that out of the box when you add your account. Never seen that before on my other android tabs or phone. I was seeing tons of favorites from my pc on my Nexus 7, not browsing history. Funny as they don't show up in my chrome browser on my Nexus 7. I even removed my google account from the device and the bookmarks still show up in the listview which has hundreds of urls from my pc favs as opposed to the 6 bookmarks I have on the device. Now I know. – Jaz Aug 17 '12 at 21:11