0

I have a webview that looks like this

WebView webview = new WebView(this);
        setContentView(webview);
        webview.loadUrl("https://myurl.com/");
        webview.setWebViewClient(new MyWebViewClient());


private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Toast.makeText(LoginActivityWebView.this, url, Toast.LENGTH_SHORT).show();
                return false;

        }
    }

When i change my URL to google everything works great, i can navigate to different sites and everything works.

When I put in my URl it is supposed to link to myurl2, but when I click it the toast prints myurl instead and the page juts reloads (not helpful!).

Any idea as to how this could happen and where shouldOverrideUrlLoading gets its url from?

If i load myurl in a browser and the user clicks a button then it works correctly.

If i load myurl in a webview, but open a browser on links pressed, then when the link is pressed it opens myurl on in a broswer and if you click the button again it correctly opens myurl2 (super weird).

Any ideas?

2
  • Your question is quite confusing, can you just tell me which URL you want to open in your webview? myUrl1 or myUrl2 ? Commented Jun 21, 2018 at 12:44
  • unfortunately its client privileged :( What do you find difficult to follow? I open up one website my client owns that has a button that should navigate to a second website he owns. Commented Jun 21, 2018 at 12:46

2 Answers 2

2

If the URL is opening in Chrome properly, you should consider adding, webView.getSettings().setJavaScriptEnabled(true) to your code and try again.

Sign up to request clarification or add additional context in comments.

Comments

2

You can get the loaded URL from

mWebView.setWebViewClient(new WebViewClient() {

public void onPageFinished(WebView view, String url) {
    // do your stuff here
}
});

3 Comments

yeh i can get the url, the problem is that it is serving the wrong url. If I open the same website in a browser it serves the correct url
Are you opening in desktop browser or mobile browser? because URL may be different for mobile as well as desktop browser (due to screen compatible)
mobile, did you read the bottom of my opening thread? i think i have worked out the problem though, its cutting off all the parameters, is that expected?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.