我对AdMob的新'Consent SDK'有疑问; integration guide表示将以下内容放入 onCreate ...
public class MainActivity extends Activity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
ConsentInformation consentInformation = ConsentInformation.getInstance(context);
String[] publisherIds = {"pub-xxxxxxxxxxxxxxxx"};
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
// User's consent status successfully updated.
}
@Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// User's consent status failed to update.
}
});
...
}
...
}
然后拨打电话:
ConsentInformation.getInstance(context).isRequestLocationInEeaOrUnknown()
我遇到的问题是当应用首次安装/启动时,isRequestLocationInEeaOrUnknown()始终返回'false'(我 am 顺便说一句,在EEA中。)
如果我退出应用并重新启动它,它会返回'true' - 这是正确的。如果我进入我的设备设置并在我的应用上执行“清除数据”并重新启动它,则会再次返回“false”。
显然这令人担忧,因为我向EEA / Swizerland用户显示我自己的自定义同意对话框,而不是我的ROW。这需要在首次发布时发生。
有趣的是,我尝试在我的AsyncTask' doInBackground 方法中调用 isRequestLocationInEeaOrUnknown()(我在onCreate中关闭此ASync)然后 首次启动时返回'true',就像在ASync的'onPostExecute'方法中调用它一样。只是在onCreate中对它进行的调用没有(在Async启动之前或之后)。
我知道这是早期的事情,但有没有人偶然发现了类似的问题?
答案 0 :(得分:1)
我面对同样的问题,有些国家是正确的,有些则不是。 我也尝试了“https://adservice.google.com/getconfig/pubvendors”
答案 1 :(得分:1)
在调用isRequestLocationInEeaOrUnknown()
回调之后,您必须调用onConsentInfoUpdated
。
此值是由requestConsentInfoUpdate()
异步检索的,因此在第一次启动时不正确,但是会对其进行缓存,因此在第二次启动时您具有正确的值。
答案 2 :(得分:0)
由于我遇到了同样的问题,而坞站有些混乱,我将尝试解释其工作原理。
添加此内容进行测试只能将其从生产环境中删除,并确保在您请求同意之前添加它们
ConsentInformation.getInstance(this@MainActivity).addTestDevice("DEVICE_ID") // add your device id for testing
ConsentInformation.getInstance(this@MainActivity).debugGeography = DebugGeography.DEBUG_GEOGRAPHY_EEA // test if user in EEA
ConsentInformation.getInstance(this@MainActivity).consentStatus = ConsentStatus.UNKNOWN // this sets the state to unknown, useful to reset the consent state in between tests careful to remove this if you want to see the flow for a returning user
请求同意状态如下:
val consentInformation = ConsentInformation.getInstance(this@MainActivity)
val publisherIds = arrayOf(ADMOB_PUBLISHER_ID)
consentInformation.requestConsentInfoUpdate(publisherIds, object: ConsentInfoUpdateListener {
override fun onFailedToUpdateConsentInfo(reason: String?) {
// consent request failed so probably you sould display non personalized ads
log("MAIN ACTIVITY", "FAILED TO UPDATE CONSENT SHOW NOT PERSONALIZED")
initializeAds(NON_PERSONALIZED)
// YOU COULD RETRY HERE OR IT WILL RETRY ON NEXT SESSION
}
override fun onConsentInfoUpdated(consentStatus: ConsentStatus?) {
when (consentStatus) {
ConsentStatus.PERSONALIZED -> {
log("MAIN ACTIVITY", "USER OPTED FOR PERSONALIZED")
// USER ALREADY GAVE HIS CONSENT FOR YOUR PUBLISHER ID SO YOU CAN DISPLAY PERSONALIZED ADS
initializeAds(PERSONALIZED)
}
ConsentStatus.NON_PERSONALIZED -> {
log("MAIN ACTIVITY", "USER OPTED FOR NON_PERSONALIZED")
// USER OPTED FOR NON_PERSONALIZED ADS SO INCLUDE THAT IN YOUR ADD REQUEST
initializeAds(NON_PERSONALIZED)
}
ConsentStatus.UNKNOWN -> {
log("MAIN ACTIVITY", "USER CONSENT STATUS IS UNKNOWN ")
// USER WAS NEVER PROMPTED TO GIVE HIS CONSENT (DEFAULT STATE FOR ALL USERS)
if (consentInformation.isRequestLocationInEeaOrUnknown) {
log("MAIN ACTIVITY", "USER IS IN EEA REQUEST CONSENT ")
// USER IS IN THE EEA AREA SO WE NEED TO REQUEST HIS CONSENT (WE SHOW THE PROMPT HERE) YOU SHOULD UPDATE CONSENT WITH HIS OPTION SO THIS FUNCTION WILL NEVER GET CALLED AGAIN
requestConsentFromUser()
} else {
log("MAIN ACTIVITY", "USER NOT IN EEA INITIALIZE ADS ")
// USER IS NOT IN EEA SO WE ARE NOT REQUIRED TO REQUEST CONSENT (YOU COULD STILL REQUEST IT IF YOU LIKE)
initializeAds(PERSONALIZED)
}
}
}
}
})