我有一个 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:
<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
- 但如果已安装,则不会打开我的应用程序!
- 这问我是否在浏览器或 PlayStore 中打开 URL,如果我扫描带有内容的 QR 码
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 许可协议
这是我为同一问题找到的解决方案: 1. 我创建了一个带有 2 个徽章的简单 http 登录页面,第一个用于 Google-play android 应用程序,第二个用于 Apple App Store 应用程序。 ( https://www.example.com/landingPage ) 2. 我在清单中添加了以下几行(如上所述):
因此,当您第一次捕捉到二维码时,您将通过浏览器被引导至登录页面,并可以选择要下载和安装的应用程序。接下来,当您捕捉到二维码时,设备会向您显示用于执行它的应用程序列表,您会在那里找到刚刚安装的应用程序。这对我来说很好