您的位置:首页 > 移动开发

android app通过webview打开其他app

2017-03-13 13:42 627 查看
我们通过webview打开那些不是http等开头的链接,会报找不到网址的问题。而如果我们想要通过那些链接打开外部app的话,就需要在方法里面加判断了。如果有其他方法,请留言...

对了,记得打开其他app时要判断手机是否安装该app,否则会蹦。

public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("test","webactivity..url:"+url);
if(!url.startsWith("http"))
{
Log.d("test","非http开头..url:"+url);
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
boolean isInstall = getPackageManager().queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY).size()>0;
Log.d("test","是否安装要跳转的app:"+isInstall);
if(isInstall)
{
startActivity(intent);
finish();
}
return true;
}
web.loadUrl(url);
return  true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: