Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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())?

like image 375
Gibson Avatar asked Oct 18 '11 21:10

Gibson


People also ask

How do I go back in WebView?

Android App Development for Beginners This example demonstrate about How to enable back button in android webview. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do you intercept a URL in WebView?

Use shouldOverrideUrlLoading(WebView, WebResourceRequest) instead. if the tap in Webview is a link to custom URL, (like myurl://parameters), its not getting called.

What is a WebView URL?

The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.


2 Answers

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
like image 129
eldy Avatar answered Sep 17 '22 13:09

eldy


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

like image 35
kabuko Avatar answered Sep 21 '22 13:09

kabuko