How do I test GDPR consent form?

31 views Asked by At

In the code below I show the consent form and when the consent is gathered I call initializeMobileAdsSdk(unit_id) that initializes (if it is not initialized yet) my Ad SDK and starts to show ads, otherwise I call quitGracefully() that exits the app.

private void initializeMobileAdsSdkWithConsentForm(java.lang.String unit_id)
{
    // Create a ConsentRequestParameters object.
    ConsentRequestParameters params = new ConsentRequestParameters
        .Builder()
        .build();

    consentInformation = UserMessagingPlatform.getConsentInformation(this);
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        (ConsentInformation.OnConsentInfoUpdateSuccessListener) () ->
        {
            UserMessagingPlatform.loadAndShowConsentFormIfRequired(
                this,
                (ConsentForm.OnConsentFormDismissedListener) loadAndShowError ->
                {
                    if (loadAndShowError != null)
                    {
                        Log.w(TAG, String.format("Consent form has been dismissed. Error: %s: %s",
                            loadAndShowError.getErrorCode(),
                            loadAndShowError.getMessage()));

                        quitGracefully();
                    }
                    else
                    {
                        Log.d(TAG, "Consent has been gathered.");

                        if (consentInformation.canRequestAds())
                        {
                            Log.d(TAG, "Calling initializeMobileAdsSdk from ConsentForm.OnConsentFormDismissedListener.");

                            initializeMobileAdsSdk(unit_id);
                        }
                    }
                }
            );
        },
        (ConsentInformation.OnConsentInfoUpdateFailureListener) requestConsentError ->
        {
            Log.w(TAG, String.format("Consent gathering failed. %s: %s",
                requestConsentError.getErrorCode(),
                requestConsentError.getMessage()));

                Log.d(TAG, "Calling initializeMobileAdsSdk from ConsentInformation.OnConsentInfoUpdateFailureListener.");

                initializeMobileAdsSdk(unit_id);
        });

    // Check if you can initialize the Google Mobile Ads SDK in parallel
    // while checking for new consent information. Consent obtained in
    // the previous session can be used to request ads.
    if (consentInformation.canRequestAds())
    {
        Log.d(TAG, "Calling initializeMobileAdsSdk from initializeMobileAdsSdkWithConsentForm.");

        initializeMobileAdsSdk(unit_id);
    }
}

I am not sure if this code correct because on all my devices the form actually is not shown but I get "Calling initializeMobileAdsSdk from ConsentForm.OnConsentFormDismissedListener." in the debug output.

How do I make the form appear to test this code?

EDIT1

Consent form does not appear on a firebase test device:

enter image description here

0

There are 0 answers