通过扫描QR码启动应用程序或Play商店

D. *_*ler 7 android qr-code google-play

我有一个包含名称的Android应用程序my.test.app.我想生成一个二维码,其中:

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

有可能这样做,以便任何Android QR扫描仪可以处理上述操作吗?我找不到一个能够实现两者的问题/答案......谢谢!

编辑 - 到目前为止我做了什么我 将以下内容添加到我的"App to open"清单中:

<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>
Run Code Online (Sandbox Code Playgroud)

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

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

我只是尝试在我的Manifest的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"/>

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

Dan*_*nai 2

您可以创建一个可由您的应用程序识别的 URL,并自动打开它(您可以在清单中声明这些)。您可以让该页面显示类似“正在将您重定向到 Google Play...”之类的内容,然后在几秒钟内重定向。

因此,如果他们安装了应用程序,URL 将触发打开它,如果未打开,它将保留在浏览器中并重定向到 Google Play。