Android:使用Admob的同意SDK获取用户的位置 [英] Android: Getting user's location using Admob's Consent SDK
问题描述
我对AdMob的新同意的SDK 有疑问; 集成指南表示将以下内容放入 onCreate ...
I have an issue with AdMob's new 'Consent SDK'; the integration guide says to put the following into 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(我在EEA中是 am )。
The problem I'm having is that when the app is first installed/launched, isRequestLocationInEeaOrUnknown() always returns 'false' (I am in the EEA by the way).
如果我然后退出应用并重新启动它,它返回 true-这是正确的。如果然后进入设备设置并在应用程序上执行清除数据并重新启动,则它再次返回 false。
If I then exit the app and re-launch it, it returns 'true' - this is correct. If I then go into my device settings and perform a 'clear data' on my app and re-launch it, once again it returns 'false'.
很明显,这是令人担忧的是,我向EA / Swizerland用户显示自己的自定义同意对话框而不是ROW。
Obviously this is worrying as I am showing my own custom consent dialog to EEA/Swizerland users than I am the ROW. And this needs to happen on first launch.
有趣的是,我尝试将对 isRequestLocationInEeaOrUnknown()的调用放在AsyncTask的 doInBackground中方法(我在onCreate中启动了该ASync),然后它像在ASync的 onPostExecute方法中对其进行的调用一样,在第一次启动时会返回 true。只是(在异步开始之前或之后)在onCreate上对其进行了调用。
Interestingly, I tried putting the call to isRequestLocationInEeaOrUnknown() in my AsyncTask' doInBackground method (I kick this ASync off in onCreate) and then it does return 'true' on first-launch as do calls to it made in the ASync's 'onPostExecute' method. It's just that calls made to it in onCreate do not (before or after the Async starts).
我知道这是早期的事情,但是有人偶然发现了与此类似的问题?
I know it's early days, but has anyone stumbled upon similar issues with this?
推荐答案
您必须在<$ c $之后调用 isRequestLocationInEeaOrUnknown()
调用c> onConsentInfoUpdated 回调。
You must call isRequestLocationInEeaOrUnknown()
after onConsentInfoUpdated
callback is called.
此值由 requestConsentInfoUpdate()
,因此在第一次启动时不正确,但是会对其进行缓存,因此在第二次启动时您具有正确的值。
This value is retrieved asynchronously by requestConsentInfoUpdate()
, so it is not correct at first launch, but it is then cached so on second launch you have correct value.
这篇关于Android:使用Admob的同意SDK获取用户的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!