通过Html⽹页调⽤本地安卓(android)app程序代码1、⾸先在编写⼀个简单的html页⾯
复制代码代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="m://my/">打开app</a><br/>
</body>
</html>
2、在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"
android:scheme="m" />
</intent-filter>
⽰例截图如下:
然后使⽤“⼿机浏览器”或者“webview”的⽅式打开这个本地的html⽹页,点击“打开APP”即可成功开启本地的指定的app
只能打开就没什么意思了,最重要的是,我们要传递数据,那么怎么去传递数据呢?
我们可以使⽤上述的⽅法,把⼀些数据传给本地app,那么⾸先我们更改⼀下⽹页,代码修改后:
复制代码代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
简易安卓app开发<a href="m://my/?arg0=0&arg1=1">打开app</a><br/>
</body>
</html>
(1).假如你是通过浏览器打开这个⽹页的,那么获取数据的⽅式为:
复制代码代码如下:
Uri uri = getIntent().getData();  String test1= QueryParameter("arg0");  String test2= QueryParameter("arg1");
(2)如果使⽤webview访问该⽹页,获取数据的操作为:
复制代码代码如下:
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {      Uri uri=Uri.parse(url);
Scheme().equals("m")&&Host().equals("my")){              String QueryParameter("arg0");
String QueryParameter("arg1");
}else{
view.loadUrl(url);
}
return true;
}
});

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。