LibGdx AdMob广告不可见。没有刷新广告

时间:2016-01-14 21:35:29

标签: android libgdx admob

我已经按照本教程:AdMob integration for LibGDX Android projects发现了一个问题。一切都很好,但我没有看到横幅。有什么想法吗?

logcat的

01-14 22:33:22.453 3138-3138/com.reiz3n.ihatespace.android I/Ads: Scheduling ad refresh 60000 milliseconds from now.
01-14 22:34:22.453 3138-3138/com.reiz3n.ihatespace.android I/Ads: Ad is not visible. Not refreshing ad.
01-14 22:34:22.463 3138-3138/com.reiz3n.ihatespace.android I/Ads: Scheduling ad refresh 60000 milliseconds from now.

AndroidLauncher

public class AndroidLauncher extends AndroidApplication implements AdsController {

private static final String BANNER_AD_UNIT_ID = "xxxxxxxxxxxxxxxxxxxxxxx";

AdView adView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

    View gameView = initializeForView(new IhateSpace(this), config);
    setupAds();

    // Define the layout
    RelativeLayout layout = new RelativeLayout(this);

    layout.addView(gameView, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);


    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    layout.addView(adView, params);

    setContentView(layout);


}

public void setupAds() {
    adView = new AdView(this);
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId(BANNER_AD_UNIT_ID);


    adView.setVisibility(View.INVISIBLE);
    adView.setBackgroundColor(0xff000000); // black
    // adView.setBackgroundColor(Color.TRANSPARENT); // transparent



}

@Override
public void showBannerAd() {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            adView.setVisibility(View.VISIBLE);
            AdRequest.Builder builder = new AdRequest.Builder();
            builder.addTestDevice("C0F358A60027941F44126ED98B0B67BF");
            AdRequest ad = builder.build();
            adView.loadAd(ad);
        }
    });
}

@Override
public void hideBannerAd() {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            adView.setVisibility(View.INVISIBLE);
        }
    });

}

@Override
protected void onPause() {
    adView.pause();
    super.onPause();
}

@Override
protected void onResume() {
    super.onResume();
    adView.resume();
}
}

IhateSpace类

public class IhateSpace extends Game {

//Virtual Screen size and Box2D Scale(Pixels Per Meter)
public static final int V_WIDTH = 960; //10 800 1920
public static final int V_HEIGHT = 540  ; //6 480 1080
public static final float PPM = 0.005f;

private ImageProvider imageProvider;

public SpriteBatch batch;
public BitmapFont font;

private AdsController adsController;

public IhateSpace(AdsController adsController){
    this.adsController = adsController;
}


@Override
public void create () {
    batch = new SpriteBatch();
    imageProvider = new ImageProvider();


    // Use libGDX's default Arial font
    font = new BitmapFont();
    Settings.load();

    adsController.showBannerAd();
    //this.setScreen(new MainMenuScreen(this, imageProvider, adsController));


}



@Override
public void render () {
    super.render(); // important!

    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

}

public void dispose() {
    batch.dispose();
    font.dispose();
}
}

仅显示红色屏幕。谢谢你的帮助。

编辑:我设法改变了一些东西。现在我明白了:

01-15 01:13:37.213 31032-31032/com.reiz3n.ihatespace.android I/AdCheck: APS: blockAdView: com.google.android.gms.ads.AdView{2d5c9d6a G.E..... ......I. 0,0-0,0}

就像:

01-15 01:53:00.083 2975-3038/com.reiz3n.ihatespace.android I/Toggle: Click!  <---- Banner hided
01-15 01:53:06.673 2975-3038/com.reiz3n.ihatespace.android I/Toggle: Click!  <---- Banner showed (theoretically, it doesn't show up really)
01-15 01:53:06.673 2975-2975/com.reiz3n.ihatespace.android I/AdCheck: APS: blockAdView: com.google.android.gms.ads.AdView{2da90ab0 G.E..... ......I. 0,0-0,0}
01-15 01:53:07.623 2975-3038/com.reiz3n.ihatespace.android I/Toggle: Click!  <---- Banner hided
01-15 01:53:08.223 2975-3038/com.reiz3n.ihatespace.android I/Toggle: Click!  <---- Banner showed (theoretically, it doesn't show up really)
01-15 01:53:08.223 2975-2975/com.reiz3n.ihatespace.android I/AdCheck: APS: blockAdView: com.google.android.gms.ads.AdView{2da90ab0 G.E..... ......I. 0,0-0,0}
01-15 01:53:45.813 2975-2975/com.reiz3n.ihatespace.android I/Ads: Ad is not visible. Not refreshing ad.
01-15 01:53:45.813 2975-2975/com.reiz3n.ihatespace.android I/Ads: Scheduling ad refresh 60000 milliseconds from now.
01-15 01:54:45.813 2975-2975/com.reiz3n.ihatespace.android I/Ads: Ad is not visible. Not refreshing ad.
01-15 01:54:45.813 2975-2975/com.reiz3n.ihatespace.android I/Ads: Scheduling ad refresh 60000 milliseconds from now.
01-15 01:55:08.473 2975-3038/com.reiz3n.ihatespace.android I/Toggle: Click! <---- Banner hided
01-15 01:55:09.173 2975-3038/com.reiz3n.ihatespace.android I/Toggle: Click! <---- Banner showed (theoretically, it doesn't show up really)
01-15 01:55:09.173 2975-2975/com.reiz3n.ihatespace.android I/AdCheck: APS: blockAdView: com.google.android.gms.ads.AdView{2da90ab0 G.E..... ......I. 0,0-0,0}}

完整日志:

01-15 12:09:31.590 23017-23017/com.reiz3n.ihatespace.android I/Hwaps: APS: version is 2.3
01-15 12:09:31.590 23017-23017/com.reiz3n.ihatespace.android W/ApsUserFeedback: APS: User feedback is not supported
01-15 12:09:31.590 23017-23017/com.reiz3n.ihatespace.android W/ApsLdfGameIdentify: APS: Ldf game identify is not supported
01-15 12:09:31.590 23017-23017/com.reiz3n.ihatespace.android W/ApsLtrGameIdentify: APS: Ltr game identify is not supported
01-15 12:09:31.610 23017-23066/com.reiz3n.ihatespace.android I/Toggle: Click!
01-15 12:09:31.610 23017-23017/com.reiz3n.ihatespace.android I/AdCheck: APS: blockAdView: com.google.android.gms.ads.AdView{6286df3 G.E..... ......I. 0,0-0,0}
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported profile 64 for video/avc
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported profile 64 for video/avc
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported profile 64 for video/avc
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported profile 64 for video/avc
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported profile 64 for video/avc
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported profile 64 for video/avc
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported profile 64 for video/avc
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android I/VideoCapabilities: Unsupported profile 16384 for video/mp4v-es
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android I/VideoCapabilities: Unsupported profile 16384 for video/mp4v-es
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android W/AudioCapabilities: Unsupported mime audio/ffmpeg
01-15 12:09:31.730 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported mime video/ffmpeg
01-15 12:09:31.740 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported mime video/x-pn-realvideo
01-15 12:09:31.740 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported mime video/mpeg
01-15 12:09:31.740 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported mime video/mpeg2
01-15 12:09:31.750 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unrecognized profile/level 32768/2 for video/mp4v-es
01-15 12:09:31.750 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported mime video/vc1
01-15 12:09:31.750 23017-23017/com.reiz3n.ihatespace.android W/VideoCapabilities: Unsupported mime video/x-flv
01-15 12:09:31.770 23017-23017/com.reiz3n.ihatespace.android I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
01-15 12:09:31.780 23017-23165/com.reiz3n.ihatespace.android I/OMXClient: Using client-side OMX mux.
01-15 12:09:31.820 23017-23169/com.reiz3n.ihatespace.android W/art: No such thread id for suspend: 27
01-15 12:09:31.890 23017-23017/com.reiz3n.ihatespace.android I/WebViewFactory: Loading com.android.webview version 37 (eng.jenkins-arm64) (code 199992)
01-15 12:09:31.920 23017-23017/com.reiz3n.ihatespace.android I/LibraryLoader: Loading: webviewchromium
01-15 12:09:31.920 23017-23017/com.reiz3n.ihatespace.android I/LibraryLoader: Time to load native libraries: 5 ms (timestamps 8049-8054)
01-15 12:09:31.920 23017-23017/com.reiz3n.ihatespace.android I/LibraryLoader: Expected native library version number "",actual native library version number ""
01-15 12:09:31.930 23017-23017/com.reiz3n.ihatespace.android I/LibraryLoader: Expected native library version number "",actual native library version number ""
01-15 12:09:31.930 23017-23017/com.reiz3n.ihatespace.android I/chromium: [INFO:library_loader_hooks.cc(106)] Chromium logging enabled: level = 0, default verbosity = 0
01-15 12:09:31.950 23017-23017/com.reiz3n.ihatespace.android I/BrowserStartupController: Initializing chromium process, renderers=0
01-15 12:09:31.950 23017-23017/com.reiz3n.ihatespace.android W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-15 12:09:31.980 23017-23189/com.reiz3n.ihatespace.android W/AudioManagerAndroid: Requires BLUETOOTH permission
01-15 12:09:31.990 23017-23017/com.reiz3n.ihatespace.android W/chromium: [WARNING:resource_bundle.cc(315)] locale_file_path.empty()
01-15 12:09:31.990 23017-23017/com.reiz3n.ihatespace.android I/chromium: [INFO:aw_browser_main_parts.cc(63)] Load from apk succesful, fd=62 off=155148 len=3312
01-15 12:09:32.000 23017-23017/com.reiz3n.ihatespace.android I/chromium: [INFO:aw_browser_main_parts.cc(78)] Loading webviewchromium.pak from, fd:63 off:228796 len:643667
01-15 12:09:32.080 23017-23017/com.reiz3n.ihatespace.android I/Ads: Starting ad request.
01-15 12:09:32.590 23017-23198/com.reiz3n.ihatespace.android W/chromium: [WARNING:proxy_service.cc(901)] PAC support disabled because there is no system implementation
01-15 12:09:32.590 23017-23017/com.reiz3n.ihatespace.android W/chromium: [WARNING:data_reduction_proxy_settings.cc(403)] SPDY proxy OFF at startup
01-15 12:09:32.590 23017-23198/com.reiz3n.ihatespace.android W/chromium: [WARNING:proxy_service.cc(901)] PAC support disabled because there is no system implementation
01-15 12:09:32.760 23017-23017/com.reiz3n.ihatespace.android W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-15 12:09:32.770 23017-23017/com.reiz3n.ihatespace.android W/AwContents: onDetachedFromWindow called when already detached. Ignoring
01-15 12:09:32.780 23017-23017/com.reiz3n.ihatespace.android W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-15 12:09:32.780 23017-23017/com.reiz3n.ihatespace.android W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-15 12:09:33.310 23017-23228/com.reiz3n.ihatespace.android I/chromium: [INFO:SkFontConfigInterface_android.cpp(227)] ---- system font and fallback font files specify a duplicate font /system/fonts/NotoSansCherokee-Regular.ttf, skipping the second occurrence
01-15 12:09:33.370 23017-23017/com.reiz3n.ihatespace.android I/Ads: Scheduling ad refresh 60000 milliseconds from now.
01-15 12:09:33.370 23017-23228/com.reiz3n.ihatespace.android I/chromium: [INFO:SkUtilsArm.cpp(179)] Device supports ARM NEON instructions!
01-15 12:09:33.560 23017-23017/com.reiz3n.ihatespace.android W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-15 12:09:33.560 23017-23017/com.reiz3n.ihatespace.android W/AwContents: onDetachedFromWindow called when already detached. Ignoring
01-15 12:09:33.570 23017-23017/com.reiz3n.ihatespace.android W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-15 12:09:33.570 23017-23017/com.reiz3n.ihatespace.android W/art: Attempt to remove local handle scope entry from IRT, ignoring
01-15 12:09:33.580 23017-23017/com.reiz3n.ihatespace.android I/Ads: Ad finished loading.
01-15 12:09:33.590 23017-23251/com.reiz3n.ihatespace.android I/System: core_booster, getBoosterConfig = false
01-15 12:09:33.590 23017-23251/com.reiz3n.ihatespace.android I/System.out: [CDS]rx timeout:60000
01-15 12:09:33.590 23017-23251/com.reiz3n.ihatespace.android I/System.out: [socket][0] connection csi.gstatic.com/173.194.113.119:443;LocalPort=58796(60000)
01-15 12:09:33.590 23017-23251/com.reiz3n.ihatespace.android I/System.out: [CDS]connect[csi.gstatic.com/173.194.113.119:443] tm:60
01-15 12:09:33.620 23017-23017/com.reiz3n.ihatespace.android I/chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
01-15 12:09:33.620 23017-23017/com.reiz3n.ihatespace.android I/chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
01-15 12:09:33.650 23017-23251/com.reiz3n.ihatespace.android I/System.out: [socket][/10.116.245.132:58796] connected
01-15 12:09:33.650 23017-23251/com.reiz3n.ihatespace.android I/System: core_booster, getBoosterConfig = false
01-15 12:09:33.810 23017-23017/com.reiz3n.ihatespace.android I/chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)

2 个答案:

答案 0 :(得分:0)

添加以下行:

adView.invalidate();

到您的节目功能。

答案 1 :(得分:0)

我反对这个错误几个小时。我得到了工作的旗帜,但它后来消失了,显示了一次,然后又消失了。只有100%工作的东西是将广告网络改为StartApp,所以如果有人出现同样的问题,我强烈建议更换广告提供商,而不是像我一样浪费2天。