Android WebView获取上一个链接的路径

 /**
     * 拿到上一页的路径
     */

        WebBackForwardList backForwardList = mViewBinding.webview.copyBackForwardList();
        if (backForwardList != null && backForwardList.getSize() != 0) {
            //当前页面在历史队列中的位置
            int currentIndex = backForwardList.getCurrentIndex();
            WebHistoryItem historyItem =
                    backForwardList.getItemAtIndex(currentIndex - 1);
            if (historyItem != null) {
                String backPageUrl = historyItem.getUrl();
//                Logger.t("111").d("拿到返回上一页的url"+backPageUrl);
                mViewBinding.webview.goBack();
                //你的处理逻辑.......
             
            }
        }
    

在项目中也遇到了 测过了也没问题 所以就分享出来 溜了溜了

你可能感兴趣的:(Android,Android,Studio)