0

I followed the guide on the Android docs but for some reason nothing is showing when i start my app. I even tried logging the listeners but nothing is showing up in logcat.

I also changed the ad technology in admob setting to Custom set of ad technology providers, but still not working.

My code

 ConsentInformation consentInformation = ConsentInformation.getInstance(getApplicationContext());
        ConsentInformation.getInstance(getApplicationContext()).addTestDevice("6AE7D8950FE9E464D988F340C0D625B0");
        ConsentInformation.getInstance(getApplicationContext()).
                setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
        String[] publisherIds = {""};
        consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
            @Override
            public void onConsentInfoUpdated(ConsentStatus consentStatus) {
                // User's consent status successfully updated.
                Log.d(TAG,"onConsentInfoUpdated");
            }

            @Override
            public void onFailedToUpdateConsentInfo(String errorDescription) {
                // User's consent status failed to update.
                Log.d(TAG,"onFailedToUpdateConsentInfo");
            }
        });

        form = new ConsentForm.Builder(this, privacyUrl)
                .withListener(new ConsentFormListener() {
                    @Override
                    public void onConsentFormLoaded() {
                        // Consent form loaded successfully.
                        Log.d(TAG,"form loaded!");
                        form.show();
                    }

                    @Override
                    public void onConsentFormOpened() {
                        // Consent form was displayed.
                    }

                    @Override
                    public void onConsentFormClosed(
                            ConsentStatus consentStatus, Boolean userPrefersAdFree) {
                        // Consent form was closed.
                    }

                    @Override
                    public void onConsentFormError(String errorDescription) {
                        // Consent form error.
                        Log.d(TAG,"form error!");
                    }
                })
                .withPersonalizedAdsOption()
                .withNonPersonalizedAdsOption()
                .withAdFreeOption()
                .build();

        form.load();

Gradle

dependencies {
        classpath 'com.google.gms:google-services:4.3.2'
   }



implementation 'com.google.android.ads.consent:consent-library:1.0.7'
implementation 'com.google.android.gms:play-services-plus:17.0.0'
implementation 'com.google.android.gms:play-services-ads:18.2.0'

EDIT

I tried it on a project which was pre android x and now it calls the listener onFailedToUpdateConsentInfo.

With following error message:

onFailedToUpdateConsentInfoCould not parse Event FE preflight response.

Searched a bit and found this could be because of an invalid pub id, but i'm certain i'm using the right one.

Vince VD
  • 1,506
  • 17
  • 38

2 Answers2

0

1) I think you forget to check isRequestLocationInEeaOrUnknown() method. It will return true If user already agreed to the consent. In this case, you don't need to ask it again. I think you already agreed to consent.

wrap your code with

if(ConsentInformation.getInstance(context).isRequestLocationInEeaOrUnknown()){
     //setup admob
}else{
     //Ask for consent
}

2) You have to call form.show(); to present the form to the user, check Google Doc

Anu Martin
  • 711
  • 1
  • 9
  • 20
  • I call it in onConsentFormLoaded() – Vince VD Oct 11 '19 at 09:21
  • does consent-library:1.0.7 support Android X? Because i migrated to it. I tried it on a project pre android x and now it calls onFailedToUpdateConsentInfo but gives error message onFailedToUpdateConsentInfoCould not parse Event FE preflight response. – Vince VD Oct 11 '19 at 10:50
0

I was still using test app id and test ad ids, remove them and change it with your id's and make sure you use it as a testdevice so you don't violate admob policies.

Like this

   adLoader.loadAd(new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build());
Vince VD
  • 1,506
  • 17
  • 38