WebView得到致命:jni_android.cc(233)]错误

时间:2017-12-21 11:37:29

标签: android webview chromium

我的webView有问题。 当用户选择点击网站上的链接时,我使用此解决方案,打开本机whatsapp等信使:

  @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Log.d(LOG_TAG, "shouldOverrideUrlLoading: " + url);
        if (url.contains("tel:")) {
            startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
            return true;
        } else if (url.startsWith("whatsapp:")
                || url.startsWith("viber:")
                || url.startsWith("telegram:")) {

            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);

            } catch (android.content.ActivityNotFoundException e) {
                Log.e(LOG_TAG, "Error with " + url + ": " + e.toString());
                Toast.makeText(getApplicationContext(), getString(R.string.app_not_install), Toast.LENGTH_SHORT).show();
            } catch (Exception q){
                q.printStackTrace();
            }
            return true;
        }
        if (Uri.parse(url).getHost().equals(URL)) {
            // This is my web site, so do not override; let my WebView load the page
            return super.shouldOverrideUrlLoading(view, url);
        }
        return super.shouldOverrideUrlLoading(view, url);
    }

但是,如果我点击"电报"例如,电报应用程序未安装在我的设备上,导致下一个错误。



 A/chromium: [FATAL:jni_android.cc(233)] Check failed: false. Please include Java exception stack in crash report
 W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
 W/google-breakpad: Chrome build fingerprint:
 W/google-breakpad: 1.0
 W/google-breakpad: 1
 W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
 A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 15585 (moilov.filipapp)




我该如何解决?

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码。

protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        context = WebviewActivity.this;

        mPullRefreshWebView = (PullToRefreshWebView) findViewById(R.id.wv);
        mWebView = mPullRefreshWebView.getRefreshableView();

        tvError.setVisibility(View.GONE);
        mWebView.setVisibility(View.VISIBLE);

        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setBuiltInZoomControls(true);

        dialog = ProgressDialog.show(context, "", "Please wait,", true);

        url = "https://google.co.in";

        if (objCommon.isOnline(context)) {
            tvError.setVisibility(View.GONE);
            mWebView.setVisibility(View.VISIBLE);
            mWebView.setWebViewClient(new SampleWebViewClient());
            mWebView.loadUrl(url);
        } else {
            Toast.makeText(context, clsCommon.NETWORK_ERROR_MSG, Toast.LENGTH_SHORT).show();
            tvError.setVisibility(View.VISIBLE);
            mWebView.setVisibility(View.GONE);
            if (dialog.isShowing()) dialog.dismiss();
        }

        tvError.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (objCommon.isOnline(context)) {
                    mWebView.getSettings().setJavaScriptEnabled(true);
                    mWebView.getSettings().setBuiltInZoomControls(true);

                    dialog = ProgressDialog.show(context, "", "Please wait,", true);

                    mWebView.setWebViewClient(new SampleWebViewClient());
                    mWebView.loadUrl(url);

                    //setting.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
                } else {
                    Toast.makeText(context, clsCommon.NETWORK_ERROR_MSG, Toast.LENGTH_SHORT).show();
                    tvError.setVisibility(View.VISIBLE);
                    mWebView.setVisibility(View.GONE);
                    if (dialog.isShowing()) dialog.dismiss();
                }
            }
        });

        mWebView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                // Activities and WebViews measure progress with different scales.
                // The progress meter will automatically disappear when we reach 100%
                //setProgress(progress * 1000);

                if (progress == 100)
                {
                    if (dialog.isShowing()) dialog.dismiss();

                    mPullRefreshWebView.onRefreshComplete();

                    if (objCommon.isOnline(context))
                    {
                        tvError.setVisibility(View.GONE);
                        mWebView.setVisibility(View.VISIBLE);
                    }
                    else
                    {
                        tvError.setVisibility(View.VISIBLE);
                        mWebView.setVisibility(View.GONE);
                    }
                }
            }

            @Override
            public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
                //Toast.makeText(context, "test : "+message, Toast.LENGTH_LONG).show();
                return super.onJsAlert(view, url, message, result);
            }
        });
    }

private class SampleWebViewClient extends WebViewClient
    {
        private Uri mCapturedImageURI;
        private int FILECHOOSER_RESULTCODE=11;
        private ValueCallback<Uri> mUploadMessage;

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) 
        {
            view.loadUrl(url);
            return true;
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) 
        {
            tvError.setVisibility(View.VISIBLE);
            mWebView.setVisibility(View.GONE);
            if(dialog.isShowing())dialog.dismiss();
        }

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

            if(objCommon.isOnline(context)) 
                tvError.setVisibility(View.GONE);
            else 
                tvError.setVisibility(View.VISIBLE); 
        }

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

            if(dialog.isShowing())dialog.dismiss();
        }
    }