15

我有这样的要求,Android Pit 应用商店已经实现了类似的要求。

我需要使用移动网页(PHP 和 JS)检查 Android 应用程序是否已安装在设备上,如果已安装,请立即启动该应用程序。

这些是安卓坑使用的中间页面。

未安装应用程序时- http://www.androidpit.com/en/android/market/app-center-mobile?pname=com.ocito.laredoute

当应用程序已经安装时- http://www.androidpit.com/en/qrdl/com.mobage.ww.a692.Bahamut_Android

有谁知道如何实现这个?

4

5 回答 5

22

幸运的是,出于明显的隐私原因,这是不可能的。

您可以做的最接近的做法是在应用程序中拥有一个具有<intent-filter>某种 URL 结构的活动,并在移动网站中拥有一个指向匹配 URL 的链接。

如果用户单击链接并安装了应用程序,则该活动将成为用户的选择器选项。

如果用户单击该链接但未安装应用程序,或者他们从选择器中选择坚持使用 Web 浏览器,则将显示该 URL 处存在的任何网页(例如,如何下载应用程序的说明)。

于 2012-10-12T11:21:43.057 回答
20

有一种方法可以实现这一点。找到了这个答案

出于安全和隐私原因,您无法检测是否安装了特定应用程序。但是,如果已安装,您可以打开应用程序,如果未安装,您可以打开其 Google Play 页面。

为此,您必须在应用程序的主要活动上创建一个意图过滤器,以便在调用给定 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.VIEW" />
    </intent-filter>
</activity> 

说明:当用户导航到http://www.myurl.com/openmyapp时,如果安装了应用程序,则会创建一个意图并显示 Activity。

但是如果用户没有安装应用程序怎么办?然后你需要在你的http://www.myurl.com/openmyapp/index.html上创建一个重定向页面。当用户到达这个地址时,你的服务器必须重定向到 market://details?id=com.your.app.package。

这样,当用户导航到http://www.myurl.com/openmyapp后没有创建 Intent 时,Web 服务器将调用另一个 URL。反过来,该 URL 将直接在应用程序页面上打开设备上的 Google Play。

于 2014-12-03T14:54:07.597 回答
1

的情况下

<data
    android:host="www.myurl.com"
    android:pathPrefix="/openmyapp"
    android:scheme="http" >
</data>

它会询问用户通过哪种方式打开内容。

在此处输入图像描述

为避免这种情况或避免将您的应用程序连接到某个 url,您可以使用 PHP 和 JS 做另一个技巧来实现它。

  1. 您必须在应用的主要活动上创建一个意图过滤器,如下所示:
<intent-filter android:label="filter_react_native">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="MyCustomScheme" android:host="MyCustomHost" />
</intent-filter>
  1. 创建 PHP 文件redirect_to_app.php,如果用户安装了应用程序,该文件将起作用。
<?php
header('Location: MyCustomScheme://MyCustomHost');
  1. check_redirect_to_app.php创建必须为尚未安装您的应用程序的用户显示的HTML/PHP 文件。
...
<a href="https://play.google.com/store/apps/details?id=YOUR_APP_PACKAGE_NAME">Please install the application</a>
...

<script>
    location.href = '...redirect_to_app.php';
</script>
  1. 将用户重定向到check_redirect_to_app.php. check_redirect_to_app.php将尝试MyCustomScheme://MyCustomHost自动重定向到。如果找不到这样的应用程序,它将继续显示check_redirect_to_app.php内容。
于 2019-07-09T21:22:24.263 回答
1

您可以使用手机上的浏览器执行此操作

 intent://scan/#Intent;scheme=clashofclans;package=com.supercell.clashofclans;S.browser_fallback_url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.supercell.clashofclans&amp;%26referrer%3Dkinlan;end

 intent://scan/#Intent;scheme=vnd.youtube://www.youtube.com/watch?v=QXhoNI4O99A;package=com.google.android.youtube;S.browser_fallback_url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.google.android.youtube&amp;%26referrer%3Dkinlan;end

你也可以试试这个

有问题的应用程序必须具有 AndroidManifest 部落冲突// 或其他方案中的方案

于 2020-06-23T07:09:06.913 回答
0

有一个更好的把戏。您将查看 URL 是否返回 404,表示未找到。如果没有安装应用程序,URL 将不起作用。

于 2020-04-14T05:27:37.680 回答