0

I am trying to access a.com, which in turn redirects me to b.com and loads it in the webview.

How do I just get the address that a.com redirects to without loading anything in the webview?

String postData = "session=" + session; webView.postUrl(urlPassedFromArguments, EncodingUtils.getBytes(postData, "base64")); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if (isAdded() && getActivity() != null) Toast.makeText(getActivity(), description, Toast.LENGTH_SHORT).show(); } @Override public void onPageFinished(WebView view, String url) { try { dialog.dismiss(); } catch (Exception e) { } super.onPageFinished(view, url); Logger.e("onPageFinished url", url); if (!resolvedUrlLoaded) { String postData = "token=" + token; webView.postUrl(url, EncodingUtils.getBytes(postData, "base64")); resolvedUrlLoaded = true; } } }); 

1 Answer 1

1

Use shouldOverrideUrlLoading:

@Override public boolean shouldOverrideUrlLoading (WebView view, String url) { // url to be loaded return true|false; } 

Returns True if the host application wants to leave the current WebView and handle the url itself, otherwise return false.

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

9 Comments

how can I obtain the redirect-to url using this?
This method gets called everytime before an URL will be loaded. So I guess you got all URLs there, including the redirect-to one. What's it your question?
also, I read in the documentation that "This method is not called for requests using the POST "method"." - what does that mean? Should I NOT call it when using POST (I am using POST) or it will not be called when I am using POST
It won't be called when using POST, just you can still override it.
You can do a request with HttpURLConnection, check httpURLConnection.getResponseCode() for "301 Redirect" and use httpURLConnection.getHeaderField("Location") to get the redirection URL for example.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.