Android WebView, how to handle redirects in app instead of opening a browser
Create a WebViewClient, and override the shouldOverrideUrlLoading method.
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
Android, catch webview redirection url
You could use a webClient and implement shouldOverrideUrlLoading to intercept all the urls
before the WebView loads them.
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Here put your code
Log.d("My Webview", url);
// return true; //Indicates WebView to NOT load the url;
return false; //Allow WebView to load url
}
});
Android, How to retrieve redirect URL from a WebView?
Finally thanks to the answer given to my question by Udi I, with a little change, i managed to find a solution to the problem. Here is the code which worked for me:
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView wView, String url) {
return (url.indexOf("some part of my redirect uri") > -1);
}
});
webView.loadUrl(myUrl); //myUrl is the initial url.
Using the above code, if there will be any url containing redirect uri, webView won't load it. Else, webView will load it. Also thanks to Kamil Kaminski.
Related Topics
Restricting Usage for an Android Key for a Google API
How to Load External Webpage in Webview
Set Inputtype for an Edittext Programmatically
Why Are There Two Build.Gradle Files in an Android Studio Project
Out of Memory Error with Bitmap
How to Draw Free Hand Polygon in Google Map V2 in Android
Prevent Status Bar for Appearing Android (Modified)
Android Ratingbar Change Star Colors
Checkbox Unchecked When I Scroll Listview on Android
What Kind of Font Files Do I Need for Modern Browsers, Android and iOS
Android Webview, How to Handle Redirects in App Instead of Opening a Browser
Getexternalstoragepublicdirectory Deprecated in Android Q
Why Doesn't Logcat Show Anything in My Android
Didn't Find Class "Com.Google.Firebase.Provider.Firebaseinitprovider"