我有一个 Android 应用程序包名称类似于 my.test.app
.我想生成一个二维码,它:
- 如果安装了我的应用:打开应用
- 如果尚未安装:在 PlayStore 中打开应用页面
有没有办法做到这一点,以便任何 Android QR 扫描仪都可以处理上述操作?我找不到一个问题/答案来实现两者...谢谢!
编辑 - 到目前为止我做了什么 我将以下内容添加到我的“要打开的应用程序” list 中:
<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 阅读器应用程序显示正确的内容,但不会打开我的应用程序!
第二次编辑 - 尝试了一些 URL
我只是尝试在我的 list 的 intent-filter 中设置一些其他 URL:
-
<data android:scheme="http" android:host="play.google.com" android:pathPrefix="/store/apps/details?id=my.test.app"/>
- 如果我扫描内容为
http://play.google.com/store/apps/details?id=my.test.app
的二维码,这会询问我是在浏览器中还是在PlayStore 中打开URL - 但如果安装了我的应用程序就打不开!
- 如果我扫描内容为
2. <data android:scheme="http" android:host="myapp.com" android:pathPrefix="/barcode"/>
- 这会在扫描二维码时打开我的应用
http://myapp.com/barcode
! 但是 问题是,扫描时未安装应用程序时没有解决方案/目标地址!也许可以通过 HTML 站点进行重定向,但我不想为此使用 HTML 服务器!
最佳答案
您可以创建一个可以被您的应用程序识别并自动打开的 URL(您可以在您的 list 中声明这些)。 您可以让该页面显示类似“正在将您重定向到 Google Play...”之类的内容,然后在几秒钟后重定向。
因此,如果他们安装了该应用程序,该 URL 将触发打开它,如果未打开,它将保留在浏览器中并重定向到 Google Play。
关于android - 通过扫描二维码启动 App 或 Play Store,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36079523/