Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Consent form is not appears in libGDX project

I am trying to implement Google Consent SDK form for my libGDX project. I have following Android class AndroidLauncher.java

public class AndroidLauncher extends AndroidApplication{

        private ConsentForm form;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            AndroidApplicationConfiguration config = new 
            AndroidApplicationConfiguration();
            initialize(new Shooter(this), config);

            ConsentInformation consentInformation = ConsentInformation.getInstance(getApplicationContext());
            String[] publisherIds = {"pub-xxxxxxxxxxxxxxxxxxxx"};
            consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
                @Override
                public void onConsentInfoUpdated(ConsentStatus consentStatus) {
                    // User's consent status successfully updated.
                    boolean inEEa = ConsentInformation.getInstance(getApplicationContext()).isRequestLocationInEeaOrUnknown();

                    if(inEEa){
                        Toast.makeText(AndroidLauncher.this, consentStatus.toString(), Toast.LENGTH_SHORT).show();
                        if(consentStatus == consentStatus.PERSONALIZED){

                        } else if(consentStatus == consentStatus.NON_PERSONALIZED){
                            Bundle extras = new Bundle();
                            extras.putString("npa", "1");

                            AdRequest request = new AdRequest.Builder()
                                    .addNetworkExtrasBundle(AdMobAdapter.class, extras)
                                    .build();
                        } else{
                            URL privacyUrl = null;
                            try {
                                // TODO: Replace with your app's privacy policy URL.
                                privacyUrl = new URL("https://privacypolicy.bitrix24.site/");
                            } catch (MalformedURLException e) {
                                e.printStackTrace();
                                // Handle error.
                            }
                            form = new ConsentForm.Builder(AndroidLauncher.this, privacyUrl)
                                    .withListener(new ConsentFormListener() {
                                        @Override
                                        public void onConsentFormLoaded() {
                                            // Consent form loaded successfully.
                                            form.show();
                                        }

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

                                        @Override
                                        public void onConsentFormClosed(
                                                ConsentStatus consentStatus, Boolean userPrefersAdFree) {
                                            // Consent form was closed.
                                            if(consentStatus == consentStatus.NON_PERSONALIZED){
                                                Bundle extras = new Bundle();
                                                extras.putString("npa", "1");

                                                AdRequest request = new AdRequest.Builder()
                                                        .addNetworkExtrasBundle(AdMobAdapter.class, extras)
                                                        .build();
                                            }
                                        }

                                        @Override
                                        public void onConsentFormError(String errorDescription) {
                                            // Consent form error.
                                        }
                                    })
                                    .withPersonalizedAdsOption()
                                    .withNonPersonalizedAdsOption()
                                    //.withAdFreeOption()
                                    .build();
                            form.load();
                        }
                    }else{

                    }
                }

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

    }

But consent form is not appears after running app.

Maybe anybody faced same problem and solved it. Could you please assist. How can I implement correctly consent dialog form for libGDX project?

Comments