Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

want to redirect webview to other intent when url loading has finished in webview android

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;
}
like image 430
user5111 Avatar asked Dec 15 '25 07:12

user5111


1 Answers

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);

    }

}

like image 176
CLucera Avatar answered Dec 16 '25 22:12

CLucera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!