当 url 在 webview android 中加载完成时,想将 webview 重定向到其他意图

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

我想在 url 加载时将 webview 重定向到另一个 activity 完全的。这是我的 webview 代码:- 这个 class 由 webview

扩展
   **   1)  This the method where I am doing code for redirecting webview to activity**

> 这是 onPagefinished 方法,其中 url 正在加载。

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

试试这个

webView.setWebViewClient(new WebViewClient() {
    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();
            }

            if (url.equals("http://nmotion.dk/paymentconfirmation/")) {
                            Intent intent = new Intent(getContext(),
                            RestaurantsListScreen.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    getContext().startActivity(intent);
                   }

            super.onPageFinished(view, url);
    }
});

您必须在 WebView WebViewCLient 中实现 on finish loader

webview.setWebViewClient(new WebViewClient(){
    @Override
    public void onPageFinished(WebView view, String url) {
        // create your intent here
        super.onPageFinished(view, url);
    }
});

使用提供的代码编辑

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

    }

}