Skip to content

Commit

Permalink
update: InstallReferrer class
Browse files Browse the repository at this point in the history
  • Loading branch information
IloveJavaa committed Feb 16, 2024
1 parent 81ef219 commit 267f563
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,22 @@ class InstallReferrer(private val context: Context) {

private suspend fun getInfo(): RefererDetails {
val referrerClient = InstallReferrerClient.newBuilder(context).build()
return suspendCancellableCoroutine {
return suspendCancellableCoroutine { continuation ->
referrerClient.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
try {
val rd = setupFinished(referrerClient, responseCode)
referrerClient.endConnection()
it.resume(rd)
continuation.resume(rd)
} catch (ex: Exception) {
it.resumeWithException(ex)
continuation.resumeWithException(ex)
}
}

// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
override fun onInstallReferrerServiceDisconnected() {
referrerClient.endConnection()
// https://stackoverflow.com/questions/48227346/kotlin-coroutine-throws-java-lang-illegalstateexception-already-resumed-but-go#comment112497041_60549898
if (it.isActive) {
it.resumeWithException(InstallReferrerException("SERVICE_DISCONNECTED"))
if (continuation.isActive) {
continuation.resumeWithException(InstallReferrerException("SERVICE_DISCONNECTED"))
}
}
})
Expand Down

0 comments on commit 267f563

Please sign in to comment.