Android – Play Store – API总安装次数

huangapple go评论68阅读模式
英文:

Android - Play Store - API total count installs

问题

我进行了大量搜索,但没有找到具体信息(可能我错了)。

我在Google Play商店上有一个正在运营的应用程序,我想通过简单调用API来获取安装总数。
据您所知,是否有一个API可以提供特定应用的安装总数?

提前感谢所有人。

英文:

I did a large search but couldn't find anything concrete (I could be wrong).

I have an app in production on the Google Play Store and I would like to have the total of the installations by simply calling an API.
As far as you know, is there an API that gives me back the total installs of a specific app?

Thanks in advance to everyone.

答案1

得分: 1

Google Play提供了非常简单的Play安装引荐库。

build.gradle中,在依赖项中添加以下行:

implementation "com.android.installreferrer:installreferrer:2.2"

然后在你的MainActivity或其他地方添加以下内容:

class MainActivity: AppCompatActivity() {

    private lateinit var referrerClient: InstallReferrerClient
  
    fun onCreate(savedInstanceState: Bundle) {
        // 其他初始化操作

        trackReferrer()
    }


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

            override fun onInstallReferrerSetupFinished(responseCode: Int) {
                when (responseCode) {
                    InstallReferrerResponse.OK -> {
                        // 连接已建立。

                        val response: ReferrerDetails = referrerClient.installReferrer
                        val referrerUrl: String = response.installReferrer
                        val referrerClickTime: Long = response.referrerClickTimestampSeconds
                        val appInstallTime: Long = response.installBeginTimestampSeconds
                        val instantExperienceLaunched: Boolean = response.googlePlayInstantParam

                        // 在此处处理引荐数据
                    }
                    InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
                        // API在当前Play商店应用不可用。
                    }
                    InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
                        // 无法建立连接。
                    }
                }
            }

            override fun onInstallReferrerServiceDisconnected() {
                // 在下一次请求Google Play时,尝试重新启动连接,调用startConnection()方法。
            }
        })
    }
}

不要忘记阅读此文档,希望这对你有所帮助。

英文:

Google play has provided the Play Install Referrer library which is very simple to use.

Inside build.gradle add this line in dependencies

implementation "com.android.installreferrer:installreferrer:2.2"

Then inside your MainActivity or some where else add this

MainActivity.kt

class MainActivity: AppCompatActivity() {

    private lateinit var referrerClient: InstallReferrerClient
  
    fun onCreate(savedInstanceState: Bundle) {
        // others initializations

        trackReferrer()
    }


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

            override fun onInstallReferrerSetupFinished(responseCode: Int) {
                when (responseCode) {
                    InstallReferrerResponse.OK -> {
                        // Connection established.

                        val response: ReferrerDetails = referrerClient.installReferrer
                        val referrerUrl: String = response.installReferrer
                        val referrerClickTime: Long = response.referrerClickTimestampSeconds
                        val appInstallTime: Long = response.installBeginTimestampSeconds
                        val instantExperienceLaunched: Boolean = response.googlePlayInstantParam

                        // do what you want to do with referral data here
                    }
                    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.
            }
        })
    }
}

Don't forget to read the doc here I hope this will help you

huangapple
  • 本文由 发表于 2023年4月11日 04:01:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980306.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定