I have a webview in my android app and would like to detect when the url changes.
I want to use this to hide the info button in the top bar when the user is on the info.php page and show it again when he is not on the info.php page.
I googled but can't find any working code, can anybody help me?
if you override this method of WebViewClient you will be able to handle url changes, and javascript url changes:
and then in your WebView set the WebViewClient
Method onPageFinished seems to work at least in modern WebViews.
I used this method:
mUrl is a fields as
String
...I had an interesting problem that brought me to this question and happy to provide a solution that may help someone else if they come this way due to a googlebingyahoo search.
mwebVew.reload() would not pick up the new URL I wanted to load once I returned from a preference screen where I either logged on the user or logged off the user. It would update the shared preferences well enough but not update and replace the url web page. So after a few hours of not seeing an answer I tried the following and it worked a real treat.
Here is the link to the doco if you want more info.
Hope it saves someone else the pain I went through, and happy to have someone tell me I should of implemented it another way.
You can use WebViewClient.shouldOverrideUrlLoading to detect every URL changes on your WebViewClient
I know I'm late to the game but I ran into this issue over and over ... I finally found a sloution which is pretty straight forward. Just override WebViewClient.doUpdateVisitedHistory
It works with all url changes even the javascript ones!
If this does not make you happy then I don't know what will :)