I want to redirect webview to another activity when url loading has completed. This is my code for webview :- this class is extended by webview
** 1) This the method where I am doing code for redirecting webview to activity**
> This is onPagefinished method where url is loading.
public void onPageFinished(WebView view, String url) {
if (url.endsWith("paymentconfirmation/"))
((DibsPaymentScreen) getContext())
.setCancelDisallowed(false);
if (callbackUrl.equals(url)
&& statusCancelled.equals(paymentData.params
.get(statusKey))) {
paymentResultListener.cancelUrlLoaded();
} else if (callbackUrl.equals(url)
&& statusAccepted.equals(paymentData.params
.get(statusKey))) {
paymentResultListener.paymentAccepted(paymentData.params);
} else if (!windowIsLoaded) {
paymentWindowLoaded();
}
super.onPageFinished(view, url);
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals("http://nmotion.dk/paymentconfirmation/")) {
Intent intent = new Intent(getContext(),
RestaurantsListScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getContext().startActivity(intent);
return true;
}
return false;
}
you have to implement the on finish loader in the WebView WebViewCLient
webview.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
// create your intent here
super.onPageFinished(view, url);
}
});
EDITED WHIT SUPPLIED CODE
public void onPageFinished(WebView view, String url) {
if (url.equals("http://nmotion.dk/paymentconfirmation/")) {
Intent intent = new Intent(getContext(), RestaurantsListScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getContext().startActivity(intent);
return true;
} else {
if (url.endsWith("paymentconfirmation/")){
((DibsPaymentScreen) getContext()).setCancelDisallowed(false);
}
if (callbackUrl.equals(url) && statusCancelled.equals(paymentData.params.get(statusKey))) {
paymentResultListener.cancelUrlLoaded();
} else if (callbackUrl.equals(url)
&& statusAccepted.equals(paymentData.params.get(statusKey))) {
paymentResultListener.paymentAccepted(paymentData.params);
} else if (!windowIsLoaded) {
paymentWindowLoaded();
}
super.onPageFinished(view, url);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With