如何显示插页式广告?

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //Log.v("SDL", "onCreate()");
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId("ca-app-pub-2188258702xxxxxxxxxxx");


        AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("XXXXXXXXXXXXX")
                .build();

        interstitial.loadAd(adRequest);

        // So we can call stuff from static callbacks
        mSingleton = this;

        // Set up the surface
        mEGLSurface = EGL10.EGL_NO_SURFACE;
        mSurface = new SDLSurface(getApplication());

        mLayout = new AbsoluteLayout(this);
        mLayout.addView(mSurface);

        setContentView(mLayout);

    }




public void displayInterstitial() {
    if (interstitial.isLoaded()) {
      interstitial.show();
    }
  }


我将sdl2用于Android,并且尝试在我的应用中展示插页式广告,但没有显示。如果我对此行发表评论setContentView(mLayout);并调用displayinterstitial()都可以正常工作,但所有sdl本机内容除外(屏幕为黑色):-)

问题是如何在Android上使用sdl制作插页式广告?

完整的SDLActivity代码在这里:
http://pastebin.com/DsRRtRS5

最佳答案

似乎您没有提到过:displayInterstitial(),在onCreate()方法中的任何位置,您确定代码执行到达了displayInterstitial()方法吗?

此外,在广告完全加载并可以显示之后,您会在某些地方返回代码。如:

@Override
  public void onReceiveAd(Ad ad) {
    Log.d("OK", "Received ad");
    if (ad == interstitial) {
      interstitial.show();
    }
  }

09-30 14:10
查看更多