Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Java脚本执行启动chrome而不是web视图_Javascript_Android_Html_Webview - Fatal编程技术网

Javascript Java脚本执行启动chrome而不是web视图

Javascript Java脚本执行启动chrome而不是web视图,javascript,android,html,webview,Javascript,Android,Html,Webview,我在“htmlString”中得到一个表单,在将它包装成html、脚本标记并加载到web视图后,我会自动重定向到chrome,这是我需要在web视图中执行的操作 这是一个payfast表单,我需要在我的android应用程序中的webview中显示支付过程 String htmlResponse = "<HTML><BODY>"+htmlString+"</BODY> " + " <script> " +

我在“htmlString”中得到一个表单,在将它包装成html、脚本标记并加载到web视图后,我会自动重定向到chrome,这是我需要在web视图中执行的操作

这是一个payfast表单,我需要在我的android应用程序中的webview中显示支付过程

String htmlResponse = "<HTML><BODY>"+htmlString+"</BODY> " +
                " <script> " +
                " document.getElementById('payfast-pay-form').submit(); " +
                " </script> " +
                " </HTML>";
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadData(htmlResponse , "text/html", "UTF-8");
String htmlResponse=“+htmlString+”“+
"  " +
“document.getElementById('payfast-pay-form').submit();”+
"  " +
" ";
WebSettings WebSettings=webView.getSettings();
setJavaScriptEnabled(true);
加载数据(htmlResponse,“text/html”,“UTF-8”);
表单数据

<form id="payfast-pay-form" action="https://sandbox.payfast.co.za/eng/process" method="post"><input type="hidden" name="merchant_id" value="243627242"><input type="hidden" name="merchant_key" value="4343343535535"><input type="hidden" name="return_url" value="https://dev.xyz.com/app/bookings/234?complete=1"><input type="hidden" name="cancel_url" value="https://dev.xyz.com/bookings/234?complete=0"><input type="hidden" name="notify_url" value="https://dev-v1-0.xyz.com/itn/settlement"><input type="hidden" name="name_first" value="Agent testing"><input type="hidden" name="name_last" value="Saloni"><input type="hidden" name="email_address" value="saloni@gmail.com"><input type="hidden" name="m_payment_id" value="234"><input type="hidden" name="amount" value="10500"><input type="hidden" name="item_name" value="We Then"><input type="hidden" name="item_description" value="xyz Booking"><input type="hidden" name="custom_int1" value=""><input type="hidden" name="custom_int2" value=""><input type="hidden" name="custom_int3" value=""><input type="hidden" name="custom_int4" value=""><input type="hidden" name="custom_int5" value=""><input type="hidden" name="custom_str1" value="settlement-amount"><input type="hidden" name="custom_str2" value=""><input type="hidden" name="custom_str3" value=""><input type="hidden" name="custom_str4" value=""><input type="hidden" name="custom_str5" value=""><input type="hidden" name="payment_method" value=""><input type="hidden" name="signature" value="afwidufuwfiurgfiwgfugfiwfw83"></form>

我的代码中缺少Web视图客户端,这就是我被重定向到Chrome浏览器的原因

WebViewClient webViewClient = new WebViewClient() {

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                showProgressDialogForAgent();
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                hideProgressDialog();
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

                Log.e("shouldUrlLoading: ", request.getUrl().getPath());
                if (request.getUrl().getPath().equals("/app/bookings/"+id))
                switch (request.getUrl().getQueryParameter("complete")) {
                    case "1":
                        onPaymentSuccess();
                        break;
                    case "0":
                        onPaymentFailure();
                        break;
                }
                return super.shouldOverrideUrlLoading(view, request);
            }
        };
        webView.setWebViewClient(webViewClient);