Discussion:
Handling Redirects in Android WebView
Rao
2012-03-11 07:54:38 UTC
Permalink
Hi,

I am developing a android application, Within the application I am
trying to Load a URL using WEBVIEW. Afer i submit the data in the
opened webpage, it gets redirected to some other URL. My requirement
is to get the complete Redirected URL within my android application.

I didnt see any events/ API methods which can be used to notify URL
Redirect.

Are there any way to listen for URL redirects within my application
and then retrieve the URL.

Thanks
Rao
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Mark Murphy
2012-03-12 11:14:29 UTC
Permalink
Redirects are handled via a WebViewClient and
shouldOverrideUrlLoading(), as are clicks on ordinary links.
Post by Rao
Hi,
I am developing a android application, Within the application I am
trying to Load a URL using WEBVIEW. Afer i submit the data in the
opened webpage, it gets redirected to some other URL. My requirement
is to get the complete Redirected URL within my android application.
I didnt see any events/ API methods which can be used to notify URL
Redirect.
Are there any way to listen for URL redirects within my application
and then retrieve the URL.
Thanks
Rao
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.7 Available!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
renuka
2012-08-14 08:05:38 UTC
Permalink
yeah, but how do tell if it's a redirect?
Unless you can tell by examining the URL, probably you can't tell if
it is a redirect.
You can create your own webclient and overrideonPageFinished(...)
onPageStarted(..) shouldOverrideUrlLoading(...)

Try these.. you we get complete redirected url...
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Eugene Prokopenko
2018-02-21 07:47:32 UTC
Permalink
*It is 2018 now, but if someone still got the problem like this, I've fount
a dicision.You can listen for URL redirects in method
shouldOverrideUrlLoading(...) it's still true, but ALL redirects webview
recognizes as clicks inside web page, as Mark Murphy mentioned before.To
prevent this (not an idial variant, but it works) you can listen touch
event on your webview,something like this:*

@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.web_view && event.getAction() == MotionEvent.ACTION_DOWN) {
isTouched = true;
}
return false;
}

*Finally, when user will click on the webpage link, you will have this
*

*isTouched* *variable. You can now use it in method like this:
*

@Override
public boolean shouldOverrideUrlLoading(WebView view, String urltoGo) {
if (isTouched) return true; /*really clicked link*/
else return false; /*just redirect*/
}
--
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/fbf91315-462a-4055-a550-50d151a32beb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Eugene P
2018-02-21 07:54:07 UTC
Permalink
*It is 2018 now, but if someone still got the problem like this, I've found
a dicision.You can listen for URL redirects in method
shouldOverrideUrlLoading(...) it's still true, but ALL redirects webview
recognizes as clicks inside web page, as Mark Murphy mentioned before.To
prevent this (not an idial variant, but it works) you can listen touch
event on your webview,something like this:*

@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.web_view && event.getAction() == MotionEvent.ACTION_DOWN) {
isTouched = true;
}
return false;
}

*Finally, when user will click on the webpage link, you will have this
*

*isTouched* *variable. You can now use it in method like this:
*

@Override
public boolean shouldOverrideUrlLoading(WebView view, String urltoGo) {
if (isTouched) return true; /*really clicked link*/
else return false; /*just redirect*/
}
--
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/d547834e-e141-4c44-b499-30a3922510a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...