我在android ads的Google adsense中有一个广告,我知道当用户点击广告时,google会创建带有有关用户信息的链接以进行跟踪。所以我想在其中获取该链接和gclid参数。我该怎么办?
我已经尝试使用Intent和Google Play安装引荐来源网址进行操作,但是Intent返回null,并且Google Play安装引荐来源网址返回空字符串,有时还返回FEATURE_NOT_SUPPORTED
这是我获取代码的意图:
val intent = this.intent
val uri = intent?.data
urlFromIntent = uri.toString()
清单:
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"
android:enabled="true"
android:exported="false" />
我的Google Play安装引荐来源代码:
mRefferClient = InstallReferrerClient.newBuilder(this).build()
mRefferClient.startConnection(object : InstallReferrerStateListener {
@SuppressLint("SwitchIntDef")
override fun onInstallReferrerSetupFinished(responseCode: Int) {
when (responseCode) {
InstallReferrerClient.InstallReferrerResponse.OK -> {
try {
if (BuildConfig.DEBUG) Log.d("InstallReferrerState", "OK")
var response = mRefferClient.installReferrer
urlFromReferClient = response.installReferrer
urlFromReferClient += ";" + response.referrerClickTimestampSeconds
urlFromReferClient += ";" + response.installBeginTimestampSeconds
mRefferClient.endConnection()
} catch (e: RemoteException) {
urlFromReferClient = e.toString()
}
}
InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
urlFromReferClient = "FEATURE_NOT_SUPPORTED"
}
InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
urlFromReferClient = "SERVICE_UNAVAILABLE"
}
}
}
override fun onInstallReferrerServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
})