GDPR SDK错误[Android工作室]

时间:2018-05-26 15:36:04

标签: java android admob main-activity

我想在我的Android Studio项目中安装GDPR SDK,但是当我在ConsentInformation的实例上调用requestConsentInfoUpdate()时,我在MainActivity中有一条错误消息。

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.
            }
        });

我在getInstance(context);上有错误:

Error : cannot resolve symbol context

1 个答案:

答案 0 :(得分:0)

您无法使用context。将其替换为getApplicationContext()this

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