开发者

AdMob onFailedToReceiveRefreshedAd not being called

I am using AdMob in my Android application and want to display a backup ad if AdMob doesn't fill. I hook into the _adView.setAdListener( but when no ad is returned, onFailedToReceiveAd does not fire like I would expect it to. When an ad is returned, onReceiveAd fires, so I know I am hooked up correctly. LogCat tells me: "No fill. Server replied that no ads are available." which seems correct. Any ideas?

public class MultipleAdView extends LinearLayout {

private AdView _adView = null;
private WebView _webView = null;
private Context _context = null;

/*
 * Constructor from parent class.
 */
public MultipleAdView(Context context) {
    super(context, null);

    _context = context;
}

public MultipleAdView(Context context, AttributeSet attrs){   
    super(context, attrs);

    _context = context;
}

public void initialize(Activity activity){
    _adView = new AdView(activity);
    _adView.setAdListener(new AdListener() {

        @Override
        public void onReceiveRefreshedAd(AdView arg0) {
            int j = 0;
            j++;
        }

        @Override
        public void onReceiveAd(AdView arg0) {
            // Just here for breakpoint - gets in here fine when ad is returned
            int j = 0;
            j++;
        }

        @Override
        public void onFailedToReceiveRefreshedAd(AdView arg0) {
            // Is never called when no ad is returned
            loadBackupAd();
        }

        @Override
        public void onFailedToReceiveAd(AdView arg0) {
            // Is never called when no ad is returned
            loadBackupAd();
        }

        private void loadBackupAd(){

            // Load backup ad here
        }
    });

 开发者_JAVA百科   addView(_adView, new LinearLayout.LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

}   

}


I figured this out recently. You should be aware that onFailedToReceiveAd and onFailedToReceiveRefreshedAd seem to have special conditions which I only determined through testing.

onFailedToReceiveAd will only be called when the initial call to get the first ad for an adview does not return any ad. If an ad is received during your first request for an ad, either with refreshAd or setting the interval, you will never get this message.

onFailedToReceiveRefreshedAd does not seem to get fired as long as the adView is automatically refreshing. It only seems to get called when refreshAd is called directly (same with onReceivedRefreshedAd). See my edit below...

Ad whirl is a better option if you're looking to spread across multiple available ad networks. It handles the rationing on the server but I've still run into problems where its seems to be out of sync with admob. Fortunately, the adwhirl code is open source so you can take a look at what its doing.


Your question caused me to do some digging. From the Android AdWhirl SDK:

 public void onReceiveAd(AdView adView) {
    Log.d(AdWhirlUtil.ADWHIRL, "AdMob success");

    AdWhirlLayout adWhirlLayout = adWhirlLayoutReference.get();
    if (adWhirlLayout == null) {
      return;
    }

    adWhirlLayout.adWhirlManager.resetRollover();
    adWhirlLayout.handler.post(new ViewAdRunnable(adWhirlLayout, adView));
    adWhirlLayout.rotateThreadedDelayed();
  }

  public void onFailedToReceiveAd(AdView adView) {
    Log.d(AdWhirlUtil.ADWHIRL, "AdMob failure");

    adView.setAdListener(null);

    AdWhirlLayout adWhirlLayout = adWhirlLayoutReference.get();
    if (adWhirlLayout == null) {
      return;
    }

    adWhirlLayout.rollover();
  }

  public void onFailedToReceiveRefreshedAd(AdView adView) {
    // Don't call adView.refreshAd so this is never called.
  }

  public void onReceiveRefreshedAd(AdView adView) {
    // Don't call adView.refreshAd so this is never called.
  }
}

This suggests to me that the mechanism for getting onFailedToReceiveRefreshedAd may indeed be to setup your own ad interval Timer using TimerTask or the sort. If you did this while disabling automatic refresh, my guess is that you'd have better luck.


You could try implementing onFailedToReceiveRefreshedAd also.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜