Android Webview: Is there a way to know what the previous URL is?

折月煮酒 提交于 2019-12-23 07:36:34

问题


Is there a way to access the history so that I know what URL the user is visiting when they hit the back button (which calls WebView.goBack())?


回答1:


This is probably the method you're looking for: WebView.copyBackForwardList




回答2:


String historyUrl="";
myWebView = (WebView) findViewById(R.id.webViewContent);
WebBackForwardList mWebBackForwardList = myWebView.copyBackForwardList();
if (mWebBackForwardList.getCurrentIndex() > 0) 
    historyUrl = mWebBackForwardList.getItemAtIndex(mWebBackForwardList.getCurrentIndex()-1).getUrl();

// Previous url is in historyUrl


来源:https://stackoverflow.com/questions/7813914/android-webview-is-there-a-way-to-know-what-the-previous-url-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!