1

My Webview works in android 4.4.4 and higher.How can I handle it in all android devices?! I mean I tried many ways to show PaymentGateWay in Webview but it`s just shown url address in webview page(Cant Load Url).how can I do it with this code?

    WebSettings webSetting = wv.getSettings();
    webSetting.setJavaScriptEnabled(true);
    webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
    final JavaScriptInterface JavaScriptInterface = new JavaScriptInterface(WebViewPaymentByBankActivity.this);
    wv.addJavascriptInterface(JavaScriptInterface, "Android");
    //webView.setWebChromeClient(new MyWebChromeClient());
    //webView.getSettings().setSupportMultipleWindows(true);
    //webSetting.setPluginState(WebSettings.PluginState.ON);
    //webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
    //webSetting.setDomStorageEnabled(true);
    webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webSetting.setAppCacheEnabled(true);

    wv.setWebChromeClient(new WebChromeClient() {

        public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result) {
            //Toast.makeText(WebViewPaymentByBankActivity.this, message, Toast.LENGTH_LONG).show();
            result.confirm();
            return true;
        }

        public void onProgressChanged(WebView view, int progress) {

            activity.setProgress(progress * 1000);
            if (progress == 100) {
            }
        }
    });

    wv.setWebViewClient(new WebViewClient() {
        @JavascriptInterface
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {

            if (!loadingFinished) {
                redirect = true;
            }
            loadingFinished = false;
            wv.loadUrl(urlNewString);
            url_result = urlNewString;
            uri = Uri.parse(url_result);
            String[] result = url_result.split("://");
            protocol = result[0];
            host = result[1];

            if (protocol.equals("inapp")) {
                if (host.equals("Error")) {
                    Intent intent = new Intent(WebViewPaymentByBankActivity.this,PaymentActivity.class);
                    startActivity(intent);
                    WebViewPaymentByBankActivity.this.finish();
                }
                else if (host.equals("Success")) {
                    Constants.ck_pay=true;
                    BasketFragment.sum = 0;
                    BasketFragment.txt_view_badge.setText("");
                    BasketFragment.txt_view_badge.setVisibility(View.GONE);
                    PaymentActivity.txt_view_pay_total.setText("0");
                    PaymentActivity.txt_view_pay_payable.setText("0");
                    WebViewPaymentByBankActivity.this.finish();
                }
            }
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (!redirect) {
                loadingFinished = true;
            }

            if (loadingFinished && !redirect) {
                //HIDE LOADING IT HAS FINISHED
            } else {
                redirect = false;
            }
            super.onPageFinished(view, url);
            view.clearCache(true);
        }

        @Override
        @JavascriptInterface
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            super.onReceivedSslError(view, handler, error);
            handler.proceed();
        }
    });
}


public class JavaScriptInterface {
    Context mContext;

    /**
     * Instantiate the interface and set the context
     */
    JavaScriptInterface(Context c) {
        mContext = c;
    }

    /**
     * Show a toast from the web page
     */
    @JavascriptInterface
    public void paymentResponse(String toast) {
        Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
    }
}


    @Override
    @JavascriptInterface
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // Check if the key event was the Back button and if there's history
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            wv.goBack();
            Intent intent = new Intent(WebViewPaymentByBankActivity.this, PaymentActivity.class);
            startActivity(intent);
            WebViewPaymentByBankActivity.this.finish();
            return true;
        }
        // If it wasn't the Back key or there's no web page history, bubble up to the default
        // system behavior (probably exit the activity)
        Intent intent = new Intent(WebViewPaymentByBankActivity.this, PaymentActivity.class);
        startActivity(intent);
        WebViewPaymentByBankActivity.this.finish();
        return super.onKeyDown(keyCode, event);
    }
5
  • what was your problem..??? Commented Jan 6, 2016 at 7:07
  • What type of problem you are facing Its an open ended question elaborate what you have tried what you want to achieve and what problem you are having other wise question may be flagged as close. Commented Jan 6, 2016 at 7:21
  • my url in webview just opens in android 4.4.4 and higher.it cant open in android 4.2.2 and lower.I set WebChromeClient and WebViewClient but doesnt open at all. Commented Jan 6, 2016 at 7:26
  • Are you trying to override an url? Commented Jan 6, 2016 at 7:45
  • Finally I found the Solution On this link! stackoverflow.com/a/34351270/5723268 Commented Jan 30, 2016 at 7:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.