您必须在Webview中设置客户端并将其传递给intent
webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if( URLUtil.isNetworkUrl(url) ) { return false; } if (appInstalledOrNot(url)) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity( intent ); } else { // do something if app is not installed } return true; } }); }
您可以使用方法检查是否已安装应用程序
private boolean appInstalledOrNot(String uri) { PackageManager pm = getPackageManager(); try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { } return false; }