Admob AdListener Example


MobileAds.initialize(getApplicationContext(), "ad unit banner");
final AdView mAdView = (AdView) findViewById(R.id.adView);
mAdView.setVisibility(View.GONE);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// showToast("Ad loaded.");
if (mAdView.getVisibility() == View.GONE) {
mAdView.setVisibility(View.VISIBLE);
}
}
@Override
public void onAdFailedToLoad(int errorCode) {
// showToast(String.format("Ad failed to load with error code %d.", errorCode));
}
@Override
public void onAdOpened() {
// showToast("Ad opened.");
}
@Override
public void onAdClosed() {
//showToast("Ad closed.");
}
@Override
public void onAdLeftApplication() {
//showToast("Ad left application.");
}
}
);
AdRequest adRequestBannner1 = new AdRequest.Builder()
.build();
mAdView.loadAd(adRequestBannner1);

Comments :

Post a Comment