How to show consent form with UserMessagingPlatform?

104 Views Asked by At

I followed a guide on Google's Documentation, to display a GDPR consent message and I can't get it to show, I used the code from the documentation, but edited the code from the Privacy options section where I added the last argument like this:

consentInformation = UserMessagingPlatform.getConsentInformation(this);
        consentInformation.requestConsentInfoUpdate(
                this,
                params,
                (ConsentInformation.OnConsentInfoUpdateSuccessListener) () -> {
                    UserMessagingPlatform.loadAndShowConsentFormIfRequired(
                            this,
                            (ConsentForm.OnConsentFormDismissedListener) loadAndShowError -> {
                                // ...

                                // Consent has been gathered.

                                if (isPrivacyOptionsRequired()) {
                                    // Regenerate the options menu to include a privacy setting.
                                    ConsentVisibility = true;
                                }
                                else ConsentVisibility = false;
                            }
                    );
                }
        , (ConsentInformation.OnConsentInfoUpdateFailureListener) requestConsentError -> {
        // Consent gathering failed.
        Log.d("ConsentF", String.format("%s: %s",
                requestConsentError.getErrorCode(),
                requestConsentError.getMessage()));
    });

The things I've tried:

  • Testing it with the options from the Testing section,
  • Testing it without the testing options,
  • Testing on an emulator and an actual device,
  • I've also made sure, that my adblocker was inactive.

The consent doesn't show up no matter what I do.¸

Edit: Consent form was also added in Google's Console.

2

There are 2 best solutions below

0
kriki200 On BEST ANSWER

For some odd reason my Consent Message got deleated, after readding it in the AdMob's Console, it didn't work with the debug settings, but it did with normal ones. So it works now.

2
ninhnau19 On

this is the way I test GDPR in my app:

            val consentInformation = UserMessagingPlatform.getConsentInformation(it)
            if (BuildConfig.DEBUG) {
                consentInformation.reset()
            }

            val builder = ConsentRequestParameters
                .Builder()
                .setTagForUnderAgeOfConsent(false)

            if (BuildConfig.DEBUG) {
                val debugSettings = activity?.let {
                    ConsentDebugSettings.Builder(it)
                        .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
                        .addTestDeviceHashedId("your_test_device_id")
                        .build()
                }
                builder.setConsentDebugSettings(debugSettings)
            }

            val params = builder.build()

            consentInformation.requestConsentInfoUpdate( ... )

consentInformation.reset() to reset if you accepted before.

setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA) to test device in EEA area

And make sure you created consent form follow document