GDPR SDK Error [ Android studio ]

939 Views Asked by At

I want to install GDPR SDK in my Android Studio project, but I have an error message in MainActivity when I call requestConsentInfoUpdate() on an instance of ConsentInformation.

public class MainActivity extends AppCompatActivity {

    InterstitialAd mInterstitialAd;
    private InterstitialAd interstitial;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /////////////////////////////////////////////////// CONSENT GDPR

        ConsentInformation consentInformation = ConsentInformation.getInstance(context);
        String[] publisherIds = {"pub-6026672754365474"};
        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.
            }
        });

I have error on getInstance(context);:

Error : cannot resolve symbol context
1

There are 1 best solutions below

3
Arash Hatami On

You can't use context. replace that with getApplicationContext() or this :

ConsentInformation consentInformation = ConsentInformation.getInstance(this);
// or    
ConsentInformation consentInformation = ConsentInformation.getInstance(getApplicationContext());