如何通过Html网页调用本地安卓app?
来源:互联网 发布:诺基亚3310软件下载 编辑:程序博客网 时间:2024/06/07 20:37
原文地址:http://www.cnblogs.com/yejiurui/p/3413796.html
如何使用html网页和本地app进行传递数据呢?经过研究,发现还是有方法的,总结了一下,大致有一下几种方式
更新一下吧,这篇日志写于2013年11月,离现在已经很久了,依然很多朋友在查阅。目前应该有更新的技术。大家也去补充一下。另外评论里面有朋友说只有webkit内核的浏览器可以使用,这个我没有去做过验证,大家使用的时候,可以参考一下。
---update in 2015.11.13
一、通过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.com/">打开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.com" 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> <a href="m://my.com/?arg0=0&arg1=1">打开app</a><br/> </body></html>
(1).假如你是通过浏览器打开这个网页的,那么获取数据的方式为:
Uri uri = getIntent().getData(); String test1= uri.getQueryParameter("arg0"); String test2= uri.getQueryParameter("arg1");
(2)如果使用webview访问该网页,获取数据的操作为:
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; }});
0 0
- 如何通过Html网页调用本地安卓app
- 如何通过Html网页调用本地安卓app?
- 如何通过Html网页调用本地安卓app?
- 如何通过Html网页调用本地安卓app?
- 如何通过Html网页调用本地安卓app?
- 如何通过Html网页调用本地安卓app?
- 如何通过Html网页调用本地安卓app?
- 如何通过Html网页调用本地安卓app?
- 如何通过Html网页调用本地安卓app?
- 如何通过Html网页调用本地安卓app?
- 通过Html网页调用本地安卓app
- 通过Html网页调用本地安卓(android)app
- 通过Html网页调用本地安卓app程序代码
- 【Unity3D自学记录】浏览器调用本地安卓App
- 网页通过js打开本地app
- 如何通过网页打开Android APP
- 如何在HTML网页中调起APP?
- android中的通过网页链接打开本地app
- hexo+github搭建个人博客
- ARToolkit Part 2: Contour Detection 详解
- UICollectionView(一)——整体总结
- nVidia Tegra K1 LVDS配置
- leapmotion文档(2):虚拟现实中的手追踪
- 如何通过Html网页调用本地安卓app?
- TCP状态机
- 找工作有哪些网站?
- vc2012编译speex (编译通过)
- WIN7登陆界面去掉下面"windows 7 旗舰版"
- collections模块里的:namedtuple
- 1006. Sign In and Sign Out (25)
- Struts2标签小结
- [openstack]proxy后devstack方式安装openstack