Getting the current URL in an Android browser

前端 未结 1 711
陌清茗
陌清茗 2021-02-06 08:22

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.B

相关标签:
1条回答
  • 2021-02-06 09:11

    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.

    Cursor webLinksCursor = 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))
                {
                    Log.i("History" , "Last page browsed " + webLinksCursor.getString(url_column_index));
                    break;
                }
            }
            webLinksCursor.moveToNext();
        }            
    }
    webLinksCursor.close();
    

    and you need the permission also

    com.android.browser.permission.READ_HISTORY_BOOKMARKS
    
    0 讨论(0)
提交回复
热议问题