0

I'm able to get searched keywords from default browser by following code.

List<SearchRecord> searchList = new LinkedList<SearchRecord>();

        ContentResolver resolver = this.getContentResolver();
        Cursor cursor = resolver.query(Browser.SEARCHES_URI, Browser.SEARCHES_PROJECTION, null, null, null);
        cursor.moveToFirst();
        if (cursor.moveToFirst() && cursor.getCount() > 0) {
            while (cursor.isAfterLast() == false) {
                SearchRecord record = new SearchRecord();

                record.setKeyword(cursor.getString(Browser.SEARCHES_PROJECTION_SEARCH_INDEX));
                record.setDate(cursor.getLong(Browser.SEARCHES_PROJECTION_DATE_INDEX));

                searchList.add(record);
                cursor.moveToNext();
            }
        }

Following code returns list of bookmarks

Uri uriCustom = Uri.parse("content://com.android.chrome.browser/bookmarks");

I'm looking for Uri of Chrome in order to get searched keywords. Do you have any idea what it is? Thanks

Hesam
  • 52,260
  • 74
  • 224
  • 365
  • i think this will be helpful http://stackoverflow.com/a/16609205/942224 – Sanket Kachhela Feb 24 '14 at 07:43
  • thanks Sanket, I saw that answer before but it's not related to my question. That one returns bookmark of default browser. I'm looking search keywords of Chrome browser. – Hesam Feb 24 '14 at 07:53
  • i am not sure but you can get search history from there also. – Sanket Kachhela Feb 24 '14 at 07:57
  • yup you are right. but i need to parse string again in order to get it. While similar way like my first code just returns keywords. – Hesam Feb 24 '14 at 08:00

1 Answers1

0
List<SearchRecord> searchList = new LinkedList<SearchRecord>();

ContentResolver resolver = this.getContentResolver();
Cursor cursor = resolver.query(Browser.SEARCHES_URI, Browser.SEARCHES_PROJECTION, ***Browser.BookmarkColumns.BOOKMARK+ " = 0"***, null, null);
cursor.moveToFirst();
if (cursor.moveToFirst() && cursor.getCount() > 0) {
    while (cursor.isAfterLast() == false) {
        SearchRecord record = new SearchRecord();
        record.setKeyword(cursor.getString(Browser.SEARCHES_PROJECTION_SEARCH_INDEX));
        record.setDate(cursor.getLong(Browser.SEARCHES_PROJECTION_DATE_INDEX));

        searchList.add(record);
        cursor.moveToNext();
    }
}
benka
  • 4,732
  • 35
  • 47
  • 58
Babar Bashir
  • 193
  • 3
  • 12