Как реализован Кодекс согласия пользователя GDPR ЕС в соответствии с новыми обновлениями IAB
Я проверяю согласие пользователя GDPR ЕС в соответствии с новыми обновлениями IAB. Я создал две функции для отображения рекламы после выполнения кода:
но я понятия не имею, какая функция подходит после выполнения кода.
Есть три следующих варианта:
НЕИЗВЕСТНЫЙ
НЕ ТРЕБУЕТСЯ
ПОЛУЧЕННЫЙ
Это мой код, он работает нормально, мне просто нужно, что можно сделать после этого
package net.ads.ump;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.ads.AdRequest;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.RequestConfiguration;
import com.google.android.ump.ConsentDebugSettings;
import com.google.android.ump.ConsentForm;
import com.google.android.ump.ConsentInformation;
import com.google.android.ump.ConsentRequestParameters;
import com.google.android.ump.UserMessagingPlatform;
import java.util.Arrays;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private ConsentInformation consentInformation;
private ConsentForm consentForm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> testDeviceIds = Arrays.asList(Config.deviceIds);
RequestConfiguration configuration =
new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);
ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this)
.setDebugGeography(ConsentDebugSettings
.DebugGeography.DEBUG_GEOGRAPHY_EEA)
.addTestDeviceHashedId(Config.deviceIds).build();
ConsentRequestParameters params = new ConsentRequestParameters
.Builder().setConsentDebugSettings(debugSettings).build();
consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(
this, params, () -> {
if (consentInformation.isConsentFormAvailable()) {
loadForm();
}
},
formError -> {
});
}
public void loadForm() {
try {
UserMessagingPlatform.loadConsentForm(
this, setConsentForm -> {
MainActivity.this.consentForm = setConsentForm;
switch (consentInformation.getConsentStatus()) {
case ConsentInformation.ConsentStatus.REQUIRED:
if (consentForm != null) {
consentForm.show(MainActivity.this,
formError -> {
loadForm();
});
}
break;
case ConsentInformation.ConsentStatus.UNKNOWN:
// What is the appropriate function?
// loadAd_GDPR_IAB(); || loadAd();
break;
case ConsentInformation.ConsentStatus.NOT_REQUIRED:
// What is the appropriate function?
// loadAd_GDPR_IAB(); || loadAd();
break;
case ConsentInformation.ConsentStatus.OBTAINED:
// What is the appropriate function?
// loadAd_GDPR_IAB(); || loadAd();
break;
}
},
formError -> {
});
} catch (Exception e) {
e.printStackTrace();
}
}
private void loadAd() {
MobileAds.initialize(this, initializationStatus -> {
});
AdView adView = findViewById(R.id.bannerId);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
private void loadAd_GDPR_IAB() {
MobileAds.initialize(this, initializationStatus -> {
});
AdView adView = findViewById(R.id.bannerId);
Bundle extras = new Bundle();
extras.putString("npa", "1");
AdRequest adRequest = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build();
adView.loadAd(adRequest);
}
}
Это две функции, которые я создал:
private void loadAd() {
MobileAds.initialize(this, initializationStatus -> {
});
AdView adView = findViewById(R.id.bannerId);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
private void loadAd_GDPR_IAB() {
MobileAds.initialize(this, initializationStatus -> {
});
AdView adView = findViewById(R.id.bannerId);
Bundle extras = new Bundle();
extras.putString("npa", "1");
AdRequest adRequest = new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build();
adView.loadAd(adRequest);
}
Кроме того, выполняется ли код только в основной активности приложения или он должен выполняться в каждом классе, в котором отображается реклама?
Это первый раз, когда я реализовал код Admob для закона о пользователях ЕС. Пожалуйста, помогите, спасибо.