为什么Admob横幅广告不会向我展示? [Android,libGDX]

时间:2017-09-19 15:00:56

标签: java android libgdx admob

我遇到了问题:

我已在我的应用中安装了Admob广告横幅,当我使用此命令构建广告时:

builder.addTestDevice(
            "0277F42DBB49E3FD56F9EFFE3C4380B4"
)

一切正常(我的意思是,我看到有类似文字的横幅"恭喜,bla-bla-bla等等"。

但是

在已发布的游戏中,当然已禁用此行(addTestDevice),但它并未显示。

清单

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hypeofpipe.westernshooter"
    android:versionCode="12"
    android:versionName="1.02">
    <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="25" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/GdxTheme" >
        <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id"/>
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
        <activity
            android:name="com.hypeofpipe.westernshooter.AndroidLauncher"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

</manifest>

AndroidLauncher.java

    public class AndroidLauncher extends AndroidApplication
            implements UrlOpener, AdHandler {

    protected AdView adView;
    private final int SHOW_ADS = 1;
    private final int HIDE_ADS = 0;

    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case SHOW_ADS:
                    adView.setVisibility(View.VISIBLE);
                    break;
                case HIDE_ADS:
                    adView.setVisibility(View.GONE);
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

        adView = new AdView(this);
        RelativeLayout layout = new RelativeLayout(this);

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

        adView.setAdListener(new AdListener(){
            @Override
            public void onAdLoaded() {
                int visibility = adView.getVisibility();
                adView.setVisibility(AdView.GONE);
                adView.setVisibility(visibility);
                AudioManager.getInstance().playSound(
                        AudioManager.getInstance().shot_missed
                );
            }
        });
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId(*here goes my unitid from admob*);

        AdRequest.Builder builder = new AdRequest.Builder();
        RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT
        );
        layout.addView(gameView);
        layout.addView(adView, adParams);
        adView.loadAd(builder.build());

        setContentView(layout);
    }

    public void openURL(String url) {
        Uri uri = Uri.parse(url);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        this.startActivity(intent);
    }

    @Override
    public void showAds(boolean show) {
        handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
    }
    }

MainClass.java

    public class MainClass extends Game {

    public static UrlOpener urlOpener;
    public static AdHandler adHandler;

    public MainClass(UrlOpener urlOpener,
                     AdHandler adHandler)
    {
        this.urlOpener = urlOpener;
        this.adHandler = adHandler;
        adHandler.showAds(false);
    }

    @Override
    public void create() {
        Assets.getInstance().load();
        Assets.getInstance().assetManager.finishLoading();
        setScreen(new ScreenModified(this));
    }

}

代码中的一些片段,其中广告被调用以显示。

MainClass.adHandler.showAds(true);

另外,我有来自我的应用程序的0个请求。

Admob

1 个答案:

答案 0 :(得分:1)

  

广告正常使用Mapper<Animal>但未获得实时广告。

请按以下步骤操作:

  1. 等待几次/小时或一天。
  2. 如果您能够加载/获取测试广告但不能加载实时广告,那么您的AdMob帐户就会出现问题。
  3. 等待仍有问题后,您需要从AdMob帐户交叉检查广告单元ID和AppId。
  4. 确保您正确设置了付款系统和/或验证了个人识别码?如果不这样做,则不会从您的帐户投放实时广告。
  5. 现在仍然存在问题,您需要在此group中发布问题以寻求帮助。