Android - Play Store - API总安装数



我做了一个大搜索,但没有找到任何具体的(我可能错了)。

我有一个应用程序在生产上的谷歌Play商店,我想通过简单地调用API安装的总数。就你所知,是否存在能够提供给我特定应用总安装量的API ?

提前感谢大家。

Google play提供了play Install Referrer库,使用起来非常简单。

build.gradle中添加这一行到dependencies

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

然后在你的MainActivity或其他地方添加这个

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.
}
})
}
}

不要忘记阅读这里的文档,我希望这会对你有所帮助

最新更新