问题
I'm running an app with AdMob ads. It works nicely, but sometimes the server can't serve an ad, so I thought about serving my own ads (plain images served from my own server). Is there any way to set a callback to the AdRequest so if the request fails, the callback is called?
回答1:
You're looking for AdMob's AdListener:
public interface AdListener {
public void onReceiveAd(Ad ad);
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error);
public void onPresentScreen(Ad ad);
public void onDismissScreen(Ad ad);
public void onLeaveApplication(Ad ad);
}
Specifically, the onFailedToReceiveAd
callback tells you when AdMob couldn't return an ad. Have your class implement this interface to get all these callbacks. Just don't forget to set the AdListener
on your AdView
:
adView.setAdListener(this);
来源:https://stackoverflow.com/questions/13027706/admob-request-fail