我们通过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;
}
转载请注明原文地址: https://ju.6miu.com/read-40758.html