簡體   English   中英

AdMob橫幅不顯示

[英]AdMob banner doesnt showing

我一直在嘗試在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);

        }
    }

問題是它不顯示廣告,我也不知道為什么。 (問題不是發布者ID,我剛剛將其更改為放在此處,在代碼中是我真正的發布者ID)

沒有人能發現問題嗎?

您似乎缺少導入中的Android支持庫。

也許這會有所幫助https://github.com/libgdx/libgdx/wiki/Google-Play-Game-Services-in-LibGDX

看看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