AdMob 25.5.0 + UMP 4.0: consentimiento EEA, init en background, proguard mínimo
This commit is contained in:
1 parent
f766e91ec2
commit
6f7bfaff9c
4 files changed
+40
-46
No files matched your search
@@ -23,6 +23,10 @@ import java.util.Calendar;
|
||||
import com.google.android.gms.ads.AdRequest;
|
||||
import com.google.android.gms.ads.AdView;
|
||||
import com.google.android.gms.ads.MobileAds;
|
||||
import com.google.android.ump.ConsentInformation;
|
||||
import com.google.android.ump.ConsentRequestParameters;
|
||||
import com.google.android.ump.FormError;
|
||||
import com.google.android.ump.UserMessagingPlatform;
|
||||
|
||||
|
||||
|
||||
@@ -104,11 +108,8 @@ public class MainActivity extends AppCompatActivity implements RobotoCalendarLis
|
||||
robotoCalendarView.setShortWeekDays(false);
|
||||
robotoCalendarView.showDateTitle(true);
|
||||
|
||||
/* Admob ads */
|
||||
MobileAds.initialize(getApplicationContext());
|
||||
AdView mAdView = (AdView) findViewById(R.id.adView);
|
||||
AdRequest adRequest = new AdRequest.Builder().build();
|
||||
mAdView.loadAd(adRequest); //request a new ad
|
||||
/* Admob ads: consentimiento UMP primero, luego init en background y banner */
|
||||
setUpConsentAndAds();
|
||||
|
||||
|
||||
|
||||
@@ -116,6 +117,31 @@ public class MainActivity extends AppCompatActivity implements RobotoCalendarLis
|
||||
registerForContextMenu(txtfraseText);
|
||||
}
|
||||
|
||||
/* Consentimiento UMP (obligatorio EEA) y tras él, init de AdMob + banner */
|
||||
private void setUpConsentAndAds() {
|
||||
ConsentRequestParameters params = new ConsentRequestParameters.Builder().build();
|
||||
ConsentInformation consentInfo = UserMessagingPlatform.getConsentInformation(this);
|
||||
consentInfo.requestConsentInfoUpdate(
|
||||
this,
|
||||
params,
|
||||
() -> UserMessagingPlatform.loadAndShowConsentFormIfRequired(
|
||||
this,
|
||||
formError -> initAdsAfterConsent()),
|
||||
formError -> initAdsAfterConsent());
|
||||
}
|
||||
|
||||
private void initAdsAfterConsent() {
|
||||
/* MobileAds.initialize en background: no bloquee el arranque */
|
||||
new Thread(() -> {
|
||||
MobileAds.initialize(getApplicationContext());
|
||||
runOnUiThread(() -> {
|
||||
AdView mAdView = findViewById(R.id.adView);
|
||||
AdRequest adRequest = new AdRequest.Builder().build();
|
||||
mAdView.loadAd(adRequest);
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
|
||||
Reference in new issue
Block a user