简体   繁体   English

我项目中的插页广告

[英]Interstitial Ads in my project

I followed this tutorial step by step, and I managed to put advertising banners, but do not get put Interstitial. 我逐步按照本教程进行操作,并设法放置了广告横幅,但没有放置插页式广告。 enter link description here 在此处输入链接说明

What happens is that the screen remains black and nothing appears, does not load or something. 发生的事情是屏幕保持黑屏,什么也没出现,没有加载或发生了什么。

I assume that my AndroidManifest is correct because it has already worked with banners, so I put the AndroidLauncher and .java my project: 我认为我的AndroidManifest是正确的,因为它已经可以使用横幅,因此我将AndroidLauncher和.java放在我的项目中:

AndroidLauncher AndroidLauncher

/* My packages and imports */

public class AndroidLauncher extends AndroidApplication implements AdsController{

    private static final String INTERSTITIAL_UNIT_ID = "My unit ID";
    InterstitialAd interstitialAd;  

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        View gameView = initializeForView(new Puzle(this), config);

        setupAds();
    }

    public void setupAds() {

        interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId(INTERSTITIAL_UNIT_ID);

        AdRequest.Builder builder = new AdRequest.Builder();
        AdRequest ad = builder.build();
        interstitialAd.loadAd(ad);
    }

    public void showInterstitialAd(final Runnable then) {
           runOnUiThread(new Runnable() {
               @Override
               public void run() {
                   if (then != null) {
                       interstitialAd.setAdListener(new AdListener() {
                           @Override
                           public void onAdClosed() {
                               Gdx.app.postRunnable(then);
                               AdRequest.Builder builder = new AdRequest.Builder();
                               AdRequest ad = builder.build();
                               interstitialAd.loadAd(ad);
                           }
                       });
                   }
                   interstitialAd.show();
               }
           });
       }

    @Override
    public boolean isWifiConnected() {

        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        return (ni != null && ni.isConnected());
    }


}

.java my project (According to the manual, you must put the call on the render method, as follows:) .java我的项目 (根据手册,您必须将调用放在render方法上,如下所示:)

public void render() {
    // TODO Auto-generated method stub
    Gdx.gl.glClearColor(0.2f,0.2f,0.2f,1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    if (adsController != null)
    {
        //System.out.println(adsController);
        //if (adsController.isWifiConnected()) {
            adsController.showInterstitialAd(new Runnable() {
                @Override
                public void run() {
                        System.out.println("Interstitial app closed");
                        Gdx.app.exit();
                }
            });
} else {
            System.out.println("Interstitial ad not (yet) loaded");
        }
    //}

} 

if I show System.out.println (ads Controller); 如果我显示System.out.println (ads Controller); to console me the following message: Interstitial ad not (yet) loaded 向我发送以下消息: Interstitial ad not (yet) loaded插入Interstitial ad not (yet) loaded

No compile errors or anything, but when I play my game, all black screen stays and does nothing. 没有编译错误或其他任何内容,但是当我玩游戏时,所有黑屏都保留了下来,什么也不做。

Please any help!! 请任何帮助!

I'm not sure but I think that your screen remains black and nothing happens due to this line in your AndroidLauncher: 我不确定,但是我认为您的屏幕仍然是黑色的,并且由于AndroidLauncher中的这一行而没有任何反应:

View gameView = initializeForView(new Puzle(this), config);

Since this is an Interstitial Ad I think that there is no need to catch the returned view to work on layouts later (this is only needed when we talk about Banner Ads). 由于这是非页内广告,因此我认为以后无需捕获返回的视图即可在布局上工作(仅当我们谈论横幅广告时才需要)。

Instead of the above line of code try to put: 代替上面的代码行,尝试输入:

    initialize(new Puzle(this), config);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM