Skip to content

Instantly share code, notes, and snippets.

@pyeongho
Created February 4, 2020 01:32
Show Gist options
  • Save pyeongho/a129329471269e1b9fcf09d6a19c24b5 to your computer and use it in GitHub Desktop.
Save pyeongho/a129329471269e1b9fcf09d6a19c24b5 to your computer and use it in GitHub Desktop.
val referrerClient: InstallReferrerClient = InstallReferrerClient.newBuilder(this).build()
referrerClient.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
when (responseCode) {
InstallReferrerClient.InstallReferrerResponse.OK -> {
// Connection established
val response: ReferrerDetails = referrerClient.installReferrer
Log.d("TAG",response.installReferrer)
referrerClient.endConnection()
}
InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
// API not available on the current Play Store app
mReferrerTrigger.onNext(Pair(false, ""))
}
InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
// Connection could not be established
}
else -> {
}
}
}
override fun onInstallReferrerServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment