我的应用程序可以知道使用哪个QR码下载它吗 [英] Can my App know which QR code was used to download it

查看:52
本文介绍了我的应用程序可以知道使用哪个QR码下载它吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase等Google Cloud服务作为后端来构建Android应用程序(SDK 24 +).

我要实现的目标是,拥有多个唯一的QR码,所有这些都会导致我的应用程序被下载.另外,同时,我希望我的应用程序知道从哪个QR下载它.
实际上,除了使用不同的QR下载我的应用程序外,我还希望它们在我的应用程序中充当唯一ID.

示例:
假设我们有5个不同的QR:QR-a,QR-b,QR-c,QR-d,QR-e.我希望所有这5个人都可以导致我的应用程序被下载,一旦下载,我希望我的应用程序知道用于下载它的QR,无论是QR-a,QR-b还是其他任何东西.

我自己的想法:
根据我的理解,第一部分(下载同一应用程序的不同QRs)应该可行,但是第二部分(应用程序知道它从哪个QR下载)甚至可行?
我知道诸如Google Analytics(分析)之类的服务会在使用QR的设备/用户上提供很多详细信息.也许,使用QR下载应用后,该应用可以查询Google Analytics(分析)用户使用哪个QR进行下载.

这是我第一次使用QR,因此我对QR的理解可能存在根本性的缺陷.
关于如何解决此问题的任何想法或想法,将不胜感激.

解决方案

如果您所有的链接都指向Google Play商店,则可以使用播放安装引荐来源库.

在安装并启动您的应用后,将依赖项添加到库中,并建立与Play商店的连接.如果连接的responseCode等于 InstallReferrerResponse.OK

,则在 onInstallReferrerSetupFinished 回调内部,访问引用数据.

  private lateinit var ReferrerClient:InstallReferrerClientReferrerClient = InstallReferrerClient.newBuilder(this).build()ReferrerClient.startConnection(object:InstallReferrerStateListener {覆盖onInstallReferrerSetupFinished(responseCode:Int){何时(responseCode){InstallReferrerResponse.OK->{//建立连接,访问您的数据val响应:ReferrerDetails = ReferrerClient.installReferrerval ReferrerUrl:字符串= response.installReferrer//TODO:评估使用哪个Play商店URL来安装您的应用}InstallReferrerResponse.FEATURE_NOT_SUPPORTED->{//API在当前的Play商店应用中不可用.}InstallReferrerResponse.SERVICE_UNAVAILABLE->{//无法建立连接.}}}重写fun onInstallReferrerServiceDisconnected(){//尝试在下一个请求重新启动连接//通过调用startConnection()方法的Google Play.}}) 

来源: https://developer.android.com/google/play/installreferrer/library

测试

要对此进行测试,您需要将应用程序上载到Play商店的内部,Alpha,Beta或生产版本中.据我所知,这不适用于内部应用共享./p>

I am building an Android application (SDK 24+), using Google Cloud services like Firebase as my back-end.

What I would like to achieve is, having multiple, unique QR codes all of which will lead to my app being downloaded. Also, at the same time, I want my app to know from which QR it was downloaded.
In effect, besides using the different QRs for downloading my app, I also want them to serve as a unique ID inside my app.

Example:
Let's say we have 5 different QRs: QR-a, QR-b, QR-c, QR-d, QR-e. I want all 5 of them to lead to my app being downloaded and, once it has been downloaded, I want my app to be aware of the QR used to download it, be it QR-a, QR-b, or whichever else.

My own thoughts:
From my understanding the first part (different QRs downloading the same app) should be doable, but is the second one (the app being aware of which QR it was downloaded from) even feasible?
I know services like Google Analytics provide a lot of detail on the device/user that used a QR. Perhaps, after downloading the app using QR, the app could query Google Analytics about which QR the user used to download it.

It's the first time I'm working with QRs, so my understanding on them may be fundamentally flawed.
Any thoughts or ideas on how to approach this problem will be appreciated.

解决方案

If all your links point to the Google Play Store, then this is doable by using the Google Play Store Install Referrer API.

Passing data to Google Play Store

Your QR codes need to point the user the store page of your app. Additionally, they need to pass more data in by using the referrer URL parameter.

One of your links could look like this:

https://play.google.com/store/apps/details?id=com.example.okariotisapp&referrer=qrdata%3DQR-a

This URL consists of the following parts:

  • Base URL for the store page of an app on the Google Play Store:
    • https://play.google.com/store/apps/details?id=
  • Your application ID:
    • com.example.okariotisapp
  • referrer URL parameter:
    • &referrer=
  • Your freely choosable key-value data. In this case with qrdata as a key and QR-a as a value (note, that %3D is the HTML URL enconding for =):
    • qrdata%3DQR-a

Access referrer data in the app

The easiest way to access the referrer data is using the Play Install Referrer Library.

Add the dependency to the library and establish a connection to the Play Store once your app has been installed and started. Inside the onInstallReferrerSetupFinished callback, access the referrer data if the responseCode for the connection is equal to InstallReferrerResponse.OK

private lateinit var referrerClient: InstallReferrerClient

referrerClient = InstallReferrerClient.newBuilder(this).build()
referrerClient.startConnection(object : InstallReferrerStateListener {

    override fun onInstallReferrerSetupFinished(responseCode: Int) {
        when (responseCode) {
            InstallReferrerResponse.OK -> {
                // Connection established, access your data
                val response: ReferrerDetails = referrerClient.installReferrer
                val referrerUrl: String = response.installReferrer
                //TODO: Evaluate which Play Store URL was used to install your app
            }
            InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
                // API not available on the current Play Store app.
            }
            InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
                // Connection couldn't be established.
            }
        }
    }

    override fun onInstallReferrerServiceDisconnected() {
        // Try to restart the connection on the next request to
        // Google Play by calling the startConnection() method.
    }
})

Source: https://developer.android.com/google/play/installreferrer/library

Testing

In order to test this, you will need to upload your app to the Play Store into the internal, alpha, beta or production track. As far as I am aware, this does not work with internal app sharing.

这篇关于我的应用程序可以知道使用哪个QR码下载它吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆