我正在寻找一种方法来查明是否从客户端Web浏览器安装了特定的应用程序.该平台是Android.
例如,我编写自己的网站并编写自己的应用程序,现在我希望用户从Android手机浏览器访问我自己的网站.浏览器查看手机上是否已安装该应用程序,如果不建议安装应用程序.我能这样做吗?
leo*_*ine 113
有一种方法可以实现这一目标.
出于安全和隐私原因,您无法检测是否安装了特定应用程序.但是,如果安装了应用程序,您就可以开启该应用程序,如果不是,则可以打开其Google Play页面.
为此,您必须在应用的主要活动上创建一个intent-filter,以便在调用给定的URL时将其打开.像这样:
<activity android:name=".MainActivity >
<intent-filter>
<data
android:host="www.myurl.com"
android:pathPrefix="/openmyapp"
android:scheme="http" >
</data>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
解释:当用户导航到http://www.myurl.com/openmyapp时,如果安装了应用程序,将创建一个intent并显示Activity.
但是如果用户没有安装应用程序呢?然后,您需要在http://www.myurl.com/openmyapp/index.html上创建重定向页面.当用户到达此地址时,您的服务器必须重定向到market://details?id=com.your.app.package.
这样,当用户导航到http://www.myurl.com/openmyapp后没有创建Intent时,Web服务器将调用另一个URL.反过来,该网址将直接在应用页面上在设备上打开Google Play.
希望能帮助到你.
Tho*_*mas 17
你的意思是从浏览器中运行的JavaScript?我认为(希望)这是不可能的.我不希望任何随机网站能够看到安装了哪些应用程序.
如果您希望用户安装特定应用,您可以在您的网站上提供市场链接:http://developer.android.com/guide/publishing/publishing.html#marketintent
编辑:在您对我的回答的评论中作出澄清后,下面会出现一个更有用的答案,其中有更多的赞成.
小智 16
我找到了一个更有用的解决方案.下面是android配置文件:
<activity android:name="me.test.html.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="xxxxx"
android:scheme="mm" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
以下是html代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function test2(){
var di = document.getElementById("di");
di.innerHTML = "app have not installed";
}
function newOpen(){//184 064 323 438
var di = document.getElementById("di");
di.innerHTML = "app have installed";
var ifc = document.getElementById("ifc");
ifc.innerHTML = "<iframe src='mm://xxxxx?a=b&c=d' onload='test2()'></iframe>";
return false;
}
</script>
</head>
<body>
<a href="#" onclick="return newOpen()">local3</a><br/>
<div id="di"></div>
<div style="display:none;" id="ifc"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这样,当用户点击标签时,如果设备安装了应用程序,那么它将不会显示允许用户选择的对话框,而是直接打开应用程序; 如果还没有安装应用程序,那么将调用js函数"test2",因此我们知道应用程序尚未安装,因此我们可以在"test2"中执行任何操作!好处是我们不需要使用标准的html模式,它会显示一个选择对话框,如果我自己使用定义的模式,页面就不会被导航到错误的页面!我是中国人,我的英语不好,希望每个人都能理解我,让其他人知道决议.
小智 5
您可以使用Android Intents.您可以构建一个意图锚点来启动应用程序.如果未安装该应用程序,则浏览器将搜索意图锚点中指定的程序包名称.我们也可以提供后备网址.
例:
<a href="intent://scan/#Intent;scheme=zxing package=com.google.zxing.client.android;end"> Take a QR code </a>
Run Code Online (Sandbox Code Playgroud)
并非所有浏览器都支持此功能.Chrome和其他一些主流浏览器都支持它.查看此链接了解更多详情.
我知道这已经晚了以为它可能对某人有所帮助.
这可能很快就会公开。
Chrome 团队 说:
在 Chrome 59 中,我们引入了一个名为getInstalledRelatedApps()的新 API 。这个新 API 可让您确定您的本机应用程序是否安装在设备上。(https://developers.google.com/web/updates/2017/04/getinstalledrelatedapps)
然而:
注意:此 API 位于 Origin Trial 之后,这意味着我们处于实验模式并正在积极寻求反馈。您必须选择您的网站加入此试用版( https://github.com/jpchase/OriginTrials/blob/gh-pages/developer-guide.md ),因为它无法在网络上广泛使用。您现在可以注册试用版( https://docs.google.com/forms/d/e/1FAIpQLSfO0_ptFl8r8G0UFhT0xhV17eabG-erUWBDiKSRDTqEZ_9ULQ/viewform?entry.1999497328=getInstalledRelatedApps )。
此功能的当前平台状态:https : //www.chromestatus.com/feature/5695378309513216
此功能的错误跟踪器问题:https ://bugs.chromium.org/p/chromium/issues/detail?id =587623
/更新 15.02.2018:
getInstalledRelatedApps()已完成试用:https : //github.com/GoogleChrome/OriginTrials/blob/gh-pages/completed-trials.md : First available in Chrome M59. Trial ends on January 30, 2018.,但尚未在稳定版 Chrome 中实现:Feature team currently considering the next steps for the feature.
| 归档时间: |
|
| 查看次数: |
74413 次 |
| 最近记录: |