【问题标题】:In andriod webview whatsapp button is not working在 android webview whatsapp 按钮不起作用
【发布时间】:2020-11-15 17:55:48
【问题描述】:

我正在尝试 android webview,但是当我想在我的手机中连接 whatsapp 应用程序时,whatsapps 按钮会出错,错误类似于 - ERR_UNKNOWN_URI_SCHEME, 以下是我的代码,请帮助我-

public class MainActivity extends AppCompatActivity {
        private WebView mywebView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mywebView=(WebView) findViewById(R.id.webview);
            mywebView.setWebViewClient(new WebViewClient());
            mywebView.loadUrl("https://royalahm.com");
            WebSettings webSettings=mywebView.getSettings();
            webSettings.setJavaScriptEnabled(true);
        }
        public class mywebClient extends WebViewClient{
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon){
                super.onPageStarted(view,url,favicon);
            }
            @Override
            public boolean shouldOverrideUrlLoading(WebView view,String url){
                if(url.startsWith("whatsapp:")) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                    startActivity(intent);
                    return true;
                }
                return false;
            }
        }
        @Override
        public void onBackPressed(){
            if(mywebView.canGoBack()) {
                mywebView.goBack();
            }
            else{
                super.onBackPressed();
            }
        }
    }

【问题讨论】:

    标签: android android-webview whatsapp tel


    【解决方案1】:

    试试这个:

    public class mywebClient extends WebViewClient{
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon){
                super.onPageStarted(view,url,favicon);
            }
            @Override
            public boolean shouldOverrideUrlLoading(WebView view,String url){
                if( url.startsWith("http:") || url.startsWith("https:") ) {
                    return false;
                }
    
                try {
                    // Otherwise allow the OS to handle things like tel, mailto, etc.
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(intent);
                }catch (Exception e){
                    Log.i("IvaExc",e.toString());
                }
                return true;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-17
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      • 2022-10-23
      • 1970-01-01
      相关资源
      最近更新 更多