Android:使用 Admob 的 Consent SDK 获取用户的位置

Android: Getting user#39;s location using Admob#39;s Consent SDK(Android:使用 Admob 的 Consent SDK 获取用户的位置)

本文介绍了Android:使用 Admob 的 Consent SDK 获取用户的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.
            }
        });
        ...
    }
    ...
}

And then make a call to:

ConsentInformation.getInstance(context).isRequestLocationInEeaOrUnknown()

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).

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'.

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.

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?

解决方案

You must call isRequestLocationInEeaOrUnknown() after onConsentInfoUpdated callback is called.

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 的 Consent SDK 获取用户的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android:使用 Admob 的 Consent SDK 获取用户的位置

基础教程推荐