通过扫描二维码启动 App 或 Play Store

新手上路,请多包涵

我有一个 Android 应用程序,其包名称类似于 my.test.app 。我想生成一个 QR 码,其中:

  • 如果安装了我的应用程序:打开应用程序
  • 如果尚未安装:在 PlayStore 中打开应用程序页面

有没有办法做到这一点,以便任何 Android QR 扫描仪都可以处理上述操作?我找不到一个问题/答案来实现两者……谢谢!

编辑-到目前为止我所做 的是将以下内容添加到我的“要打开的应用程序”清单中:

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:exported="true" >
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-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:scheme="my.test.app"/>
        </intent-filter>
    </activity>
  ...
</application>

当我生成内容为 my.test.app://test 的 QR 码并扫描它时,QR 阅读器应用程序显示正确的内容,但不会打开我的应用程序!

第二次编辑 - 尝试了一些网址

我只是试图在我的清单的 intent-filter 中设置一些其他 URL:

  1. <data android:scheme="http" android:host="play.google.com" android:pathPrefix="/store/apps/details?id=my.test.app"/>
    • 这问我是否在浏览器或 PlayStore 中打开 URL,如果我扫描带有内容的 QR 码 http://play.google.com/store/apps/details?id=my.test.app
    • 但如果已安装,则不会打开我的应用程序!

2. <data android:scheme="http" android:host="myapp.com" android:pathPrefix="/barcode"/>

  • 这会在扫描二维码时打开我的应用程序 http://myapp.com/barcode 问题是,扫描时未安装应用程序时没有解决方案/目标地址!也许可以通过 HTML 站点进行重定向,但我不想为此使用 HTML 服务器!

原文由 D. Müller 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 407
1 个回答

这是我为同一问题找到的解决方案: 1. 我创建了一个带有 2 个徽章的简单 http 登录页面,第一个用于 Google-play android 应用程序,第二个用于 Apple App Store 应用程序。 ( https://www.example.com/landingPage ) 2. 我在清单中添加了以下几行(如上所述):

     <data
                android:scheme="https"
                android:host="www.example.com"
                android:pathPrefix="/landingPage" />
</intent-filter>

  1. 我从 URL https://www.example.com/landingPage 生成了一个二维码。您最终可以在最后添加一些参数,以便将来在 App 中处理( https://www.example.com/landingPage&param1=value1 ecc.)。

因此,当您第一次捕捉到二维码时,您将通过浏览器被引导至登录页面,并可以选择要下载和安装的应用程序。接下来,当您捕捉到二维码时,设备会向您显示用于执行它的应用程序列表,您会在那里找到刚刚安装的应用程序。这对我来说很好

原文由 mattdago 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题