简体   繁体   English

AdMob横幅不显示

[英]AdMob banner doesnt showing

I have been trying to add a banner to my game on Libgdx and i have read some documentation on it and eventually wrote this code: 我一直在尝试在Libgdx上的游戏中添加横幅,并且已经阅读了一些文档,并最终编写了以下代码:

    protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    //initialize(new GameMain(), config);

    RelativeLayout layout = new RelativeLayout(this);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    View gameView = initializeForView(new GameMain(), config);
    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId("pub-xxxxxxxxxxx");
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);
    layout.addView(gameView);

    RelativeLayout.LayoutParams adParams = 
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
        adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        layout.addView(adView, adParams);
        setContentView(layout);

        }
    }

The problem is that it doesn't show the ads and i cant figure out why. 问题是它不显示广告,我也不知道为什么。 (the problem is not the publisher id i have just changed it to put it here, in the code it is my real publisher id) (问题不是发布者ID,我刚刚将其更改为放在此处,在代码中是我真正的发布者ID)

Can't anyone spot the problem? 没有人能发现问题吗?

您似乎缺少导入中的Android支持库。

maybe this helps https://github.com/libgdx/libgdx/wiki/Google-Play-Game-Services-in-LibGDX 也许这会有所帮助https://github.com/libgdx/libgdx/wiki/Google-Play-Game-Services-in-LibGDX

look bulild.gradle: 看看bulild.gradle:

project(":android") {
apply plugin: "android"

configurations { natives }

dependencies {
    compile project(":core")
    compile project(":libraries:BaseGameUtils")
    compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
    compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
    natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
    natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
    natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"

    compile 'com.android.support:appcompat-v7:20.0.+'
    compile 'com.android.support:support-v4:20.0.+'
    compile 'com.google.android.gms:play-services:5.0+'
}

}

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

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