I'm searching for a way to get the current URL a user is visiting on the android browser application.
I figured out that I can get the last visited URL from the Browser.BOOKMARKS_URI
database using the following technique:
Cursor cursor = context.getContentResolver().query(Browser.BOOKMARKS_URI,
Browser.HISTORY_PROJECTION, null, null,
Browser.BookmarkColumns.DATE + " DESC");
cursor.moveToNext();
String url = cursor.getString(Browser.HISTORY_PROJECTION_URL_INDEX);
cursor.close();
The problem with this, is that the Browser.BOOKMARKS_URI
db doesn't get updated when the user presses back in order to navigate to the previous page in the browser, and the query returns incorrect results.
See the following example:
- user navigates to www.google.com -> Query returns "www.google.com"
- user navigates to www.imdb.com -> Query returns "www.imdb.com"
- user presses back to return to www.google.com -> Query returns "www.imdb.com" (!!)
Does anyone have any idea how to return the correct url a user is viewing?
I think you did not have gone through the following approah. once try it! You can access Browsing history the same way you do that for other ContentProviders. Besides browsing history you can also get list of Bookmarks.
and you need the permission also