Update:
更新了实现方式:
2014-12-9
---------我是分割线------------------------------------------------------------------------------
原文:
最近遇到这么一个需求:
当用户在手机微端中点击一个按钮时,如果手机上已经该应用程序,则直接打开,如果没有安装,则转向应用下载页面。 再详细一点就是:通过点击网页中一个按钮,打开本地某个Activity(如果有的话)或用微端打开某个url。
查了一下文档,Android是支持这个的:
解释一下文档中的描述:scheme://host:port/path or pathPrefix or pathPattern
这里面定义的schema+host+port+(path or pathPrefix or pathPattern)能拼凑出一个http链接,包含这个filter的Activity,能处理这个http链接。
实现:
点击这个按钮:
<a id="applink1" href="">打开</a>
在 中,直接开始下载xxxx.apk。
给目标Activity增加以下filter:
<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="test.xx.com "
android:path="/demo/test.php"
android:scheme="http" />
</intent-filter>
增加该filter后,该Activity就能处理 http://test.xx.com/demo/test.php。在微端中点击“开始”,发起对该URL的请求时,如果本机安装了这个应用,系统就会弹出一个选择,询问你想使用微端打开,还是使用该应用打开,如下图:
![]()
如果本机没有安装这个应用,则直接会使用微端(多个微端的话,还需要选择一下)打开 ,微端会提示你下载应用,如下图:
![]()
|