Sparks Sh Sparks Sh - 5 months ago 27
Android Question

How to get current url in android browsers (API23)

I know that current version of API removed this functionality for reading bookmark history, before that I used to use attached function to access current URL, but unfortunately it does not work anymore, do you have any ideas how to achieve this problem?

Cursor webLinksCursor = ctx.getContentResolver().query(Browser.BOOKMARKS_URI, Browser.HISTORY_PROJECTION, null, null, Browser.BookmarkColumns.DATE + " DESC");
int row_count = webLinksCursor.getCount();

int title_column_index = webLinksCursor.getColumnIndexOrThrow(Browser.BookmarkColumns.TITLE);
int url_column_index = webLinksCursor.getColumnIndexOrThrow(Browser.BookmarkColumns.URL);

if ((title_column_index > -1) && (url_column_index > -1) && (row_count > 0))
{
webLinksCursor.moveToFirst();
while (webLinksCursor.isAfterLast() == false)
{
if (webLinksCursor.getInt(Browser.HISTORY_PROJECTION_BOOKMARK_INDEX) != 1)
{
if (!webLinksCursor.isNull(url_column_index))
{
return webLinksCursor.getString(url_column_index);
}
}
webLinksCursor.moveToNext();
}
}
webLinksCursor.close();
return null;

Answer

There is no standardized API for accessing browser history or current URLs. Even the Browser provider from past API levels did not have to be used by browser developers.

You are welcome to contact the developers of various browsers and see if they offer their own API to get what you are seeking. In general, I expect the answer to be that they do not offer such an API.