简体   繁体   English

为什么没有向我显示Admob横幅广告? [Android,libGDX]

[英]Why does an Admob banner ad doesn't show to me? [Android, libGDX]

I have a problem: 我有个问题:

I've installed an Admob ad banner in my app and when I'm using this command to builder: 我已经在我的应用中安装了Admob广告横幅,并且在使用此命令构建工具时:

builder.addTestDevice(
            "0277F42DBB49E3FD56F9EFFE3C4380B4"
)

Everything works (I mean, I see banner with similar text "congrats, bla-bla-bla, etc". 一切正常(我的意思是,我看到带有类似文字“祝贺,bla-bla-bla等”的横幅。

But. 但。

In published game, which of course has disabled this line (addTestDevice) it doesn't show. 在已发布的游戏中,当然禁用了该行(addTestDevice),但该行不会显示。

Manifest 表现

    <?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 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 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));
    }

}

Some fragment from code, where ads are called to show. 代码中的一些片段,其中需要调用广告来展示。

MainClass.adHandler.showAds(true);

Also, I have 0 requests from mine app. 另外,我有来自我的应用程序的0个请求。

AdMob广告

Ads working fine with addTestDevice(XXX) but not getting live Ads. 广告可以与addTestDevice(XXX)正常工作,但不能获得实时广告。

Follow these steps : 跟着这些步骤 :

  1. Wait for some times/hours or a day. 等待一些时间/小时或一天。
  2. If you're able to load/get test ads but not live ads, It sounds like an issue with your AdMob account. 如果您可以加载/获取测试广告,但不能加载/投放实时广告,则听起来好像是您的AdMob帐户存在问题。
  3. After waiting still having problem then you need to cross check Ad unit Id and AppId from AdMob account. 等待仍然有问题后,您需要从AdMob帐户中交叉检查广告单元ID和AppId。
  4. Make sure that you properly set up a payment system and/or verified your PIN? 确保您正确设置了付款系统和/或验证了PIN码? If they are not done, then live ads would not be served from your account. 如果未完成,则不会从您的帐户中投放实时广告。
  5. Still problem now you need to post your problem in this group for assistance. 现在仍然是问题,您需要在此组中发布问题以寻求帮助。

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

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