Commit 5c7cb3f2 authored by wanglei's avatar wanglei

...installReferrer

parent 34eee44f
......@@ -14,6 +14,7 @@ import com.base.datarecovery.help.BaseApplication
import com.base.datarecovery.help.ConfigHelper
import com.base.datarecovery.utils.ActivityManagerUtils
import com.base.datarecovery.utils.AppPreferences
import com.base.datarecovery.utils.InstallHelps
import com.base.datarecovery.utils.LogEx
import com.base.datarecovery.utils.NewComUtils
import com.google.android.gms.ads.MobileAds
......@@ -51,6 +52,7 @@ class MyApplication : BaseApplication() {
}
}
if (ifAgreePrivacy) {
InstallHelps.init()
MobileAds.initialize(this) { initializationStatus ->
}
}
......
package com.base.datarecovery.utils
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
import com.base.datarecovery.help.BaseApplication
import org.json.JSONObject
object InstallHelps {
fun init() {
val referrerClient = InstallReferrerClient.newBuilder(BaseApplication.context).build()
referrerClient.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
try {
when (responseCode) {
InstallReferrerClient.InstallReferrerResponse.OK -> {
val response = referrerClient.installReferrer
val installInfo = response.installReferrer
val obj = JSONObject()
obj.put("referrerUrl", response.installReferrer)
obj.put("referrerClickTime", response.referrerClickTimestampSeconds)
obj.put("appInstallTime", response.installBeginTimestampSeconds)
obj.put("instantExperienceLaunched", installInfo.toString())
EventUtils.event("install_referrer", ext = obj, isSingleEvent = true)
}
else -> {
EventUtils.event("install_referrer_error")
}
}
} catch (_: Exception) {
EventUtils.event("install_referrer_error")
}
}
override fun onInstallReferrerServiceDisconnected() {
}
})
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment