AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i("Admob", "Ad loaded.");
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log.i("Admob", "Ad failed to load. Error code: " + errorCode);
}
});
dependencies {
implementation 'com.google.android.gms:play-services-ads:20.2.0'
}
AdView adView = new AdView(this);
adView.setAdUnitId("YOUR_AD_UNIT_ID");
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i("Admob", "Ad loaded.");
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log.i("Admob", "Ad failed to load. Error code: " + errorCode);
}
@Override
public void onAdFailedToLoad(LoadAdError adError) {
Log.i("Admob", "Ad failed to load.
下一篇:Admob广告实施