为什么GDPR表格没有显示?
我把它放在build.gradle
:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
implementation 'com.google.android.ads.consent:consent-library:1.0.3'
这主要是:
import android.util.Log;
import com.google.ads.consent.*;
import java.net.MalformedURLException;
import java.net.URL;
ConsentForm form;
private static final String TAG = "MainActivity ----- : " ;
ConsentInformation consentInformation = ConsentInformation.getInstance(MainActivity.this);
String[] publisherIds = {"pub-9138443983781653"};
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
@Override
public void onConsentInfoUpdated(ConsentStatus consentStatus) {
// User's consent status successfully updated.
Log.d(TAG,"onConsentInfoUpdated");
switch (consentStatus){
case PERSONALIZED:
Log.d(TAG,"PERSONALIZED");
ConsentInformation.getInstance(MainActivity.this)
.setConsentStatus(ConsentStatus.PERSONALIZED);
break;
case NON_PERSONALIZED:
Log.d(TAG,"NON_PERSONALIZED");
ConsentInformation.getInstance(MainActivity.this)
.setConsentStatus(ConsentStatus.PERSONALIZED);
break;
case UNKNOWN:
Log.d(TAG,"UNKNOWN");
if(ConsentInformation.getInstance(MainActivity.this).isRequestLocationInEeaOrUnknown()){
URL privacyUrl = null;
try {
// TODO: Replace with your app's privacy policy URL.
privacyUrl = new URL("https://www.appprivacy.com/privacyurl");
} catch (MalformedURLException e) {
e.printStackTrace();
// Handle error.
}
form = new ConsentForm.Builder(MainActivity.this, privacyUrl)
.withListener(new ConsentFormListener() {
@Override
public void onConsentFormLoaded() {
// Consent form loaded successfully.
Log.d(TAG,"onConsentFormLoaded");
showform();
}
@Override
public void onConsentFormOpened() {
// Consent form was displayed.
Log.d(TAG,"onConsentFormOpened");
}
@Override
public void onConsentFormClosed(
ConsentStatus consentStatus, Boolean userPrefersAdFree) {
// Consent form was closed.
Log.d(TAG,"onConsentFormClosed");
}
@Override
public void onConsentFormError(String errorDescription) {
// Consent form error.
Log.d(TAG,"onConsentFormError");
Log.d(TAG,errorDescription);
}
})
.withPersonalizedAdsOption()
.withNonPersonalizedAdsOption()
.build();
form.load();
}else{
Log.d(TAG,"PERSONALIZED else");
ConsentInformation.getInstance(MainActivity.this)
.setConsentStatus(ConsentStatus.PERSONALIZED);
}
break;
default:
break;
}
}
@Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
// User's consent status failed to update.
Log.d(TAG,"onFailedToUpdateConsentInfo");
Log.d(TAG,errorDescription);
}
});
}
private void showform(){
if (form!=null){
Log.d(TAG,"show ok");
form.show();
}}
当我调试应用程序时,我发现该应用程序未输入:
@Override 公共无效同意信息已更新(同意状态同意状态(
代码有问题吗?如果我们想更新旧应用程序 我们应该只添加这样的简单代码还是更改每个单元?
添加以下内容:
ConsentInformation.getInstance(MainActivity.this).setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);