Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last loaded url of webview without doing a webView.goBack() in Android

I want to log the history url or last loaded url without manually storing the history urls. Is that possible?

like image 356
Arnab Chakraborty Avatar asked Oct 13 '11 16:10

Arnab Chakraborty


People also ask

How do I know if a URL is loaded in WebView?

myWebView. setWebViewClient(new MyWebViewClient()); public class MyWebViewClient extends WebViewClient { ... @Override public void onPageFinished(WebView view, String url) { // Make a note that the page has finished loading. } ... }

What can I use instead of WebView?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

How do you override a WebView?

If you want to override certain methods, you have to create a custom WebView class which extends WebView . Also, when you are inflating the WebView , make sure you are casting it to the correct type which is CustomWebView . CustomWebView webView = (CustomWebView) findViewById(R. id.

Is Android WebView deprecated?

Beginning October 5, 2021, Facebook Login will no longer support using Android embedded browsers (WebViews) for logging in users.


1 Answers

Found the answer in the docs ...

WebBackForwardList mWebBackForwardList = mWebView.copyBackForwardList();
String historyUrl = mWebBackForwardList.getItemAtIndex(mWebBackForwardList.getCurrentIndex()-1).getUrl();
like image 158
Arnab Chakraborty Avatar answered Oct 19 '22 09:10

Arnab Chakraborty