我正在尝试在我的应用程序中使用Admob,它在早期版本(如4.0及更早版本)上运行良好,但它不会在4.1及更新版本上显示。
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Set the AdListener.
adView.setAdListener(new AdListener() {
/**
* Called when an ad is clicked and about to return to the
* application.
*/
@Override
public void onAdClosed() {
Log.d(LOG_TAG, "onAdClosed");
Toast.makeText(BannerAdListener.this, "onAdClosed",
Toast.LENGTH_SHORT).show();
}
/** Called when an ad failed to load. */
@Override
public void onAdFailedToLoad(int error) {
String message = "onAdFailedToLoad: " + getErrorReason(error);
Log.d(LOG_TAG, message);
Toast.makeText(BannerAdListener.this, message,
Toast.LENGTH_SHORT).show();
}
/**
* Called when an ad is clicked and going to start a new Activity
* that will leave the application (e.g. breaking out to the Browser
* or Maps application).
*/
@Override
public void onAdLeftApplication() {
Log.d(LOG_TAG, "onAdLeftApplication");
Toast.makeText(BannerAdListener.this, "onAdLeftApplication",
Toast.LENGTH_SHORT).show();
}
/**
* Called when an Activity is created in front of the app (e.g. an
* interstitial is shown, or an ad is clicked and launches a new
* Activity).
*/
@Override
public void onAdOpened() {
Log.d(LOG_TAG, "onAdOpened");
Toast.makeText(BannerAdListener.this, "onAdOpened",
Toast.LENGTH_SHORT).show();
}
/** Called when an ad is loaded. */
@Override
public void onAdLoaded() {
Log.d(LOG_TAG, "onAdLoaded");
Toast.makeText(BannerAdListener.this, "onAdLoaded",
Toast.LENGTH_SHORT).show();
}
});
// Add the AdView to the view hierarchy.
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
layout.addView(adView);