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?
www.google.com
page, but reads it from the cache. Same happens when the user switches the tab: the history shows the latest loaded URL, not necessarily the one that is displayed. You can keep track of current URL in a WebView embedded into your app. – Presurmise