Android开发——通过扫描二维码,打开或者下载Android应用
Android开发——通过扫描二维码,打开或者下载Android应用
在实现这个功能的时候,被不同的浏览器折磨的胃疼,最后实现了勉强能用,也查考了一下其他人的博客
android实现通过浏览器点击链接打开本地应用(APP)并拿到浏览器传递的数据
android/iPhone:如何从browser直接打开应用程序或者打开应用商店(如果没有应用程序)
1、Html页面(JS不在行,这个是其他人写的)
需要留意的是Android_URL,格式需要符合[scheme]://[host]/[path]?[query]
scheme:判别启动的App。
host:适当记述
path:传值时必须的key (没有也可以)
query:获取值的Key和Value (没有也可以)
1
|
Android_URL = "myapp://www.test.com/openwith?uid=123"; |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
< html > < head > < meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" /> < meta content = "telephone=no" name = "format-detection" /> < meta name = "viewport" content = "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" /> < title >打开或下载应用</ title > < script src = "assets/plugins/jquery-1.8.3.min.js" type = "text/javascript" ></ script > </ head > < body > < a id = "vlink" onClick = "try_to_open_app()" style = "display:none" ></ a > < script > var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return { trident: u.indexOf('Trident') > -1, //IE内核 presto: u.indexOf('Presto') > -1, //opera内核 webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核 gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核 mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //是否为移动终端 ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端 android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器 iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器 iPad: u.indexOf('iPad') > -1, //是否iPad webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部 }; }() } var iOS_URL = "myapp://www.test.com_uid=123"; var Android_URL = "myapp://www.test.com/openwith?uid=123"; var mtUrl = "http://www.test.com/download"; function open_link() { window.location=mtUrl; } function try_to_open_app() { setTimeout('open_link()', 500); } //IOS if(browser.versions.iPhone){ document.getElementById("vlink").setAttribute("href",iOS_URL); document.getElementById("vlink").click(); } //Android else if(browser.versions.android){ document.getElementById("vlink").setAttribute("href",Android_URL); document.getElementById("vlink").click(); } else{ open_link(); } </ script > </ body > </ html > |
2、配置入口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<!-- 默认入口 --> < activity android:name = "net.laobanquan.im.splash.StartActivity" android:launchMode = "singleTop" android:screenOrientation = "portrait" android:theme = "@android:style/Theme.Black.NoTitleBar" > < intent-filter > < action android:name = "android.intent.action.MAIN" /> < category android:name = "android.intent.category.LAUNCHER" /> </ intent-filter > </ activity > <!-- 新建入口 --> < activity android:name = "net.test.WebStartActivity" android:screenOrientation = "portrait" > < intent-filter > < action android:name = "android.intent.action.VIEW" ></ action > < category android:name = "android.intent.category.DEFAULT" ></ category > < category android:name = "android.intent.category.BROWSABLE" ></ category > < data android:scheme = "myapp" android:host = "www.test.com" android:path = "/openwith" /> </ intent-filter > </ activity > |
3、Activity入口接受参数
1
2
3
4
5
6
7
8
9
|
String action = getIntent().getAction(); String uid = null ; if (Intent.ACTION_VIEW.equals(action)){ Uri uri = getIntent().getData(); if (uri != null ){ uid = uri.getQueryParameter( "uid" ); } } Log.d(TAG, uid); |
4、总结
如果原来点击图片的默认入口是StartActivity,那么最好新建WebStartActivity入口,除了多做“接受参数”其他和StartActivity一样
Android开发——通过扫描二维码,打开或者下载Android应用的更多相关文章
- Android开发之扫描二维码开发
原贴地址:http://www.cnblogs.com/Fndroid/p/5540688.html 二维码其实有很多种,但是我们常见的微信使用的是一种叫做QRCode的二维码,像下面这样的,可以放心 ...
- 使用扫描二维码打开app
应该不少人遇到过这种需求,扫描二维码打开app如果用户没有这个app则提示它跳转. 用网页直接来调用app是不打可能的,必须原生那边先做一些配置. 首先,安卓和苹果的调用方法是不同的. 所以我们需要先 ...
- Android之条码扫描二维码扫描
Android之条码扫描二维码扫描 二维码条形码扫描,参考技术网址: 1.Apache License 2.0 开源的ZXing项目的简化版 http://xinlanzero.iteye.com/b ...
- Android实例-实现扫描二维码并生成二维码(XE8+小米5)
相关资料: 第三方资料太大没法写在博文上,请下载CSDN的程序包. 程序包下载: http://download.csdn.net/detail/zhujianqiangqq/9657186 注意事项 ...
- [置顶]
xamarin android使用zxing扫描二维码
好久没写了,这片文章篇幅不长,概述一下在xamarin android中用 ZXing.Net.Mobile库扫描二维码读取url的示例.扫码支付,扫码登录,App上各种各样的扫码,好像没个扫码的就有 ...
- [Unity+Android]横版扫描二维码
原地址:http://blog.csdn.net/dingxiaowei2013/article/details/25086835 终于解决了一个忧伤好久的问题,严重拖了项目进度,深感惭愧!一直被一系 ...
- h5 扫描二维码打开app和点击下载功能的实现
window.onload = function () { jumpToapp() } var browser = { isAndroid: function () { return navigato ...
- android开发之集成zxing,二维码,以及扫描二维码的功能实现。带源代码下载
package cc.jiusansec.www; import com.google.zxing.WriterException; import com.zxing.activity.Capture ...
- 二维码合成,将苹果和安卓(ios和android)合成一个二维码,让用户扫描一个二维码就可以分别下载苹果和安卓的应用
因为公司推广的原因,没有合适的将苹果和安卓(ios和android)合成一个二维码的工具. 因为这个不难,主要是根据浏览器的UA进行判断,所以就自己开发了一个网站 网站名称叫:好推二维码 https ...
随机推荐
- Neutron Metering as a Service
1, /etc/neutron/neutron.conf service_plugins = router,metering notification_driver=neutron.open ...
- SAP 增强说明
转自http://blog.csdn.net/lyb_yt/article/details/8177974 (一)什么是增强(Enhancement)? 简单地说,增强就是ERP系统中标准程序的出口, ...
- 264. Ugly Number II
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- Codeforces Round #366 (Div. 2) A
A. Hulk time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- ZOJ 1089 Lotto
原题链接 题目大意:有一种抽奖游戏乐透(Lotto),规则是从1到49这49个自然数中随机抽取6个数.现在有一种简化版的游戏,先在49个数里面选出k(6<k<13)个数,然后再从这k个数里 ...
- ZOJ 1005 Jugs
原题链接 题目大意:有一大一小两个杯子,相互倒水,直到其中一个杯子里剩下特定体积的水.描述这个过程. 解法:因为两个杯子的容积互质,所以只要用小杯子不断往大杯子倒水,大杯子灌满后就清空,大杯子里迟早会 ...
- URIEncoding和useBodyEncodingForURI详解
之前关于编码的问题已经总结过两次了,有些地方写的很粗略.http://blog.itpub.net/29254281/viewspace-775925/http://blog.itpub.net/29 ...
- hdu 2795 线段树(二维问题一维化)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- JS初学之-选项卡(常见)
思路:鼠标滑过的效果直接用a:hover实现的,比较简便,缺点是在IE下不兼容. 为每一个Li添加点击事件,将每一个li用自定义属性的方法与div相匹配,重点是在点击事件内,要先遍历每一个div, ...
- JavaScript学习记录总结(五)——servlet将json数据写出去
定义teacher和student实体 json.do List<Student> stus=new ArrayList<Student>(); stus.a ...