我已经获得GDPR同意的Android同意SDK的工作版本。在物理和仿真设备上运行良好。对于仿真设备,SDK应该识别出它是仿真器,而不一定带有设备ID的显式addTestDevice
()。但是,似乎使用API 30无法识别仿真设备。解决方法是,Logcat标识我明确传递给addTestDevice
()的仿真器设备ID。下面是我的代码,就像我说的那样,它最适合API29。API30不能隐式识别模拟器。我在API 30上同时尝试了Pixel 3和Pixel XL。我想知道是否还有其他人看到过此消息,或者我应该在API 30中了解一些新知识。谢谢!
fun initializeGDPR(responseCallBack: (status:GDPRConsentResponse) -> Unit) {
val consentInformation = ConsentInformation.getInstance(context)
if (ENABLE_TEST_EEA_CONSENT)
enableEEATestDevices(consentInformation)
consentInformation.requestConsentInfoUpdate(arrayOf(context.getString(R.string.admob_publisher_id)), object : ConsentInfoUpdateListener {
override fun onConsentInfoUpdated(consentStatus: ConsentStatus) {
Log.d("ConsentHelper", "initializeGDPR:onConsentInfoUpdated: $consentStatus")
//Is user if European Union or request location is Unknown
if(consentInformation.isRequestLocationInEeaOrUnknown) {
Log.d("ConsentHelper", "initializeGDPR:isRequestLocationInEeaOrUnknown: true");
// If the returned ConsentStatus is PERSONALIZED or NON_PERSONALIZED, the user has already provided consent. Call back to initial calling routine to habdle
// If the returned ConsentStatus is UNKNOWN, load form to get consent
when (consentStatus) {
ConsentStatus.UNKNOWN -> displayGDPRConsentForm(responseCallBack)
ConsentStatus.PERSONALIZED -> {
consentResponse = GDPRConsentResponse.SHOW_PERSONAL
responseCallBack(consentResponse)
}
ConsentStatus.NON_PERSONALIZED -> {
consentResponse = GDPRConsentResponse.SHOW_NON_PERSONAL
responseCallBack(consentResponse)
}
}
} else {
Log.d("ConsentHelper", "initializeGDPR:isRequestLocationInEeaOrUnknown: false")
isEEA = false
consentResponse = GDPRConsentResponse.UNKNOWN
responseCallBack(consentResponse)
}
}
override fun onFailedToUpdateConsentInfo(errorDescription: String) {
Log.d("ConsentHelper", "initializeGDPR:onFailedToUpdateConsentInfo: $errorDescription");
errorString = errorDescription
consentResponse = GDPRConsentResponse.UNKNOWN
responseCallBack(consentResponse)
}
})
}
private fun enableEEATestDevices(consentInformation:ConsentInformation) {
consentInformation.debugGeography = DebugGeography.DEBUG_GEOGRAPHY_EEA
consentInformation.addTestDevice(CONSENT_TEST_DEVICES_1)
consentInformation.addTestDevice(CONSENT_TEST_DEVICES_2)
consentInformation.addTestDevice(CONSENT_TEST_DEVICES_3)
consentInformation.addTestDevice(CONSENT_TEST_DEVICES_4)
consentInformation.addTestDevice(CONSENT_TEST_DEVICES_5)
consentInformation.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
}