Browser Content Provider

Following code demonstrates retrieving visited website title, no. of times that website visited and whether it is bookmarked or not.

Write the following code in onCreate() method.

String[] requestedColumns = 
{
	Browser.BookmarkColumns.TITLE,
	Browser.BookmarkColumns.VISITS,
	Browser.BookmarkColumns.BOOKMARK
};
Cursor faves = managedQuery(Browser.BOOKMARKS_URI, requestedColumns,
null, null, null);
Log.d(DEBUG_TAG, "Bookmarks count: " + faves.getCount());
int titleIdx = faves.getColumnIndex(Browser.BookmarkColumns.TITLE);
int visitsIdx = faves.getColumnIndex(Browser.BookmarkColumns.VISITS);
int bmIdx = faves.getColumnIndex(Browser.BookmarkColumns.BOOKMARK);
faves.moveToFirst();
int count = 0;
while (!faves.isAfterLast())
{
	Log.d(DEBUG_TAG, "Inside while --- : " + count);
	Log.d("SimpleBookmarks",faves.getString(titleIdx) + " visited "
		+ faves.getInt(visitsIdx) + " times : "
		+ (faves.getInt(bmIdx) != 0 ? "true" : "false"));
	faves.moveToNext();
	count++;
}
Advertisements

One thought on “Browser Content Provider

  1. Hi,
    To access web history you need to use Browser class available in android.provider package.

    Try following code it may be helpful to you.

    Cursor mCur = activity.managedQuery(Browser.BOOKMARKS_URI,
    Browser.HISTORY_PROJECTION, null, null, null);
    mCur.moveToFirst();
    if (mCur.moveToFirst() && mCur.getCount() > 0) {
    while (mCur.isAfterLast() == false) {
    Log.v(“titleIdx”, mCur
    .getString(Browser.HISTORY_PROJECTION_TITLE_INDEX));
    Log.v(“urlIdx”, mCur
    .getString(Browser.HISTORY_PROJECTION_URL_INDEX));
    mCur.moveToNext();
    }
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s