首页 技术 正文
技术 2022年11月12日
0 收藏 340 点赞 4,258 浏览 1412 个字

http://www.cnblogs.com/yejiurui/p/3413796.html

一、通过html页面打开Android本地的app

1、首先在编写一个简单的html页面

通过html页面打开Android本地的app

<html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title>Insert title here</title>    </head>    <body>        <a href="m://my.com/" rel="external nofollow" >打开app</a><br/>    </body></html>

通过html页面打开Android本地的app

2、在Android本地app的配置

通过html页面打开Android本地的app

在AndroidManifest的清单文件里的intent-filte中加入如下元素:
<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="my.com"
android:scheme="m" />
</intent-filter>

通过html页面打开Android本地的app

示例截图如下:

通过html页面打开Android本地的app

然后使用“手机浏览器”或者“webview”的方式打开这个本地的html网页,点击“打开APP”即可成功开启本地的指定的app

二、如何通过这个方法获取网页带过来的数据

只能打开就没什么意思了,最重要的是,我们要传递数据,那么怎么去传递数据呢?

我们可以使用上述的方法,把一些数据传给本地app,那么首先我们更改一下网页,代码修改后:

通过html页面打开Android本地的app

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="m://my.com/?arg0=0&arg1=1" rel="external nofollow" >打开app</a><br/>
</body>
</html>

通过html页面打开Android本地的app

(1).假如你是通过浏览器打开这个网页的,那么获取数据的方式为:

Uri uri = getIntent().getData();  String test1= uri.getQueryParameter("arg0");  String test2= uri.getQueryParameter("arg1");

(2)如果使用webview访问该网页,获取数据的操作为:

通过html页面打开Android本地的app

webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uri=Uri.parse(url);
if(uri.getScheme().equals("m")&&uri.getHost().equals("my.com")){
String arg0=uri.getQueryParameter("arg0");
String arg1=uri.getQueryParameter("arg1"); }else{
view.loadUrl(url);
}
return true;
}
});

通过html页面打开Android本地的app

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289