WebView或浏览器通过Scheme调起App
2017-11-21 17:22
549 查看
WebView或浏览器通过Scheme调起App:
一、 在要调起的app中的AndroidManifes.xml文件中,在要被其它应用启动的Activity标签中添加如下拦截器:
可以只写一个host和scheme,如下:
<data
android:scheme="xieyi"
android:host="me.ricky.sample"/>
例:
xieyi://me.ricky.sample/"
具体的配置及详情可见:
http://m.blog.csdn.net/litengit/article/details/74451989
注:引用litengit的文章
二、 在html页面中添加:
例:写一个test.html页面(内容如下,)将此页面在浏览器中打开,点击“打开app”,就会跳转到app中;
test.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"content="width=device-width, user-scalable=no"/>
<linkhref="./css/bootstrap-responsive.css" rel="stylesheet">
<linkhref="./css/bootstrap.css" rel="stylesheet">
<style>
div {
padding:2px;
}
</style>
</script>
</head>
<body>
<div>
<a href="xieyi://me.ricky.sample/">打开app</a>
</div>
</body>
</html>
三、 通过webView打开app:
注意:在要打开其它app的应用中设置webVeiw:
具体的配置及详情可见:
http://blog.csdn.net/u012452490/article/details/77931430
注:引用”恢兔子”的文章
最佳实践:以上亲测可以使用,我测了20多款浏览器,只有百度浏览器打不开,根据“恢兔子”所说,个人推测可能是百度浏览器屏蔽了此类调用。
一、 在要调起的app中的AndroidManifes.xml文件中,在要被其它应用启动的Activity标签中添加如下拦截器:
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="me.ricky.sample" android:path="/userDetails" android:port="8080" android:scheme="xieyi" /> </intent-filter>
可以只写一个host和scheme,如下:
<data
android:scheme="xieyi"
android:host="me.ricky.sample"/>
例:
xieyi://me.ricky.sample/"
具体的配置及详情可见:
http://m.blog.csdn.net/litengit/article/details/74451989
注:引用litengit的文章
二、 在html页面中添加:
<a href="xieyi://me.ricky.sample/">打开app</a>
例:写一个test.html页面(内容如下,)将此页面在浏览器中打开,点击“打开app”,就会跳转到app中;
test.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"content="width=device-width, user-scalable=no"/>
<linkhref="./css/bootstrap-responsive.css" rel="stylesheet">
<linkhref="./css/bootstrap.css" rel="stylesheet">
<style>
div {
padding:2px;
}
</style>
</script>
</head>
<body>
<div>
<a href="xieyi://me.ricky.sample/">打开app</a>
</div>
</body>
</html>
三、 通过webView打开app:
注意:在要打开其它app的应用中设置webVeiw:
private MyWebViewClient mWebViewClient = null; mWebViewClient = new MyWebViewClient(); mWebView.setWebViewClient(mWebViewClient); private class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (TextUtils.isEmpty(url)) return false; // 通过webView打开其它app try { if (!url.startsWith("http") || !url.startsWith("https") || !url.startsWith("ftp")) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (isInstall(intent)) { getContext().startActivity(intent); return true; } } } catch (Exception e) { return false< 8e23 /span>; } return false; } //判断app是否安装 private boolean isInstall(Intent intent) { return MyApplication.getMyContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0; } // MyApplication.getMyContext()应当改成你自己对应的application
具体的配置及详情可见:
http://blog.csdn.net/u012452490/article/details/77931430
注:引用”恢兔子”的文章
最佳实践:以上亲测可以使用,我测了20多款浏览器,只有百度浏览器打不开,根据“恢兔子”所说,个人推测可能是百度浏览器屏蔽了此类调用。
相关文章推荐
- Android 通过点击浏览器或者内部WebView加载URL 唤起App
- 从浏览器或者Webview 中唤醒APP
- android app通过webview打开其他app
- app 中的webview控件与终端浏览器的内核不一致
- 从浏览器或者Webview 中唤醒APP
- android:如何通过chrome远程调试APP中的webView的h5代码
- 安卓app的webView加载网页后出现ERR_UNKNOWN_URL_SCHEME
- android通过webview调起支付宝app支付
- 【Android】检测是否处于Wifi环境,利用WebView实现浏览器app
- JS唤醒Android APP(包括在外部浏览器和WebView)
- 关于iOS加载webView通过webView跳转回app
- Android通过Chrome Inspect调试WebView的H5 App出现空白页面的解决方法(不需要FQ)
- 填上浏览器跳转app-webview,app没有接收跳转url的查询参数的坑
- android通过webview调起支付宝app支付
- JS唤醒Android APP(包括在外部浏览器和WebView)
- Android webview 跳到app,Android Scheme
- 【Android】检测是否处于Wifi环境,利用WebView实现浏览器app
- 通过WebView实现简单的浏览器
- JS唤醒Android APP(包括在外部浏览器和WebView)
- 用WebView秒做一款简易的浏览器app