简体   繁体   English

带有Google Play服务的AndEngine广告

[英]AndEngine ads with Google Play Services

I created an application with AndEngine that is using only one View, the game itself. 我使用AndEngine创建了一个仅使用一个视图(游戏本身)的应用程序。 It extends the SimpleBaseGameActivity, but my problem occurs on all of those: 它扩展了SimpleBaseGameActivity,但是我的问题发生在所有这些方面:

Every example that I have found on the internet does not work, and the reasons are very similar. 我在互联网上找到的每个示例都不起作用,其原因非常相似。 The example below is taken from 以下示例取自

http://www.andengine.org/forums/tutorials/admob-xml-layout-example-t3338.html#p15852 http://www.andengine.org/forums/tutorials/admob-xml-layout-example-t3338.html#p15852

@Override
protected void onSetContentView() {


    final FrameLayout frameLayout = new FrameLayout(this);
    final FrameLayout.LayoutParams frameLayoutLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
                                         FrameLayout.LayoutParams.FILL_PARENT);

    final AdView adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxx");

    adView.refreshDrawableState();
    adView.setVisibility(AdView.VISIBLE);
    final FrameLayout.LayoutParams adViewLayoutParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                                         FrameLayout.LayoutParams.WRAP_CONTENT,
                                         Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
    // getHeight returns 0
    // http://groups.google.com/group/admob-pu ... a874df3472
    int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50,
            getResources ().getDisplayMetrics ());
    // top of AD is at middle of the screen
    adViewLayoutParams.topMargin = height/2;

    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
    adView.loadAd(adRequest);

    this.mRenderSurfaceView = new RenderSurfaceView(this);
    mRenderSurfaceView.setRenderer(mEngine);

    final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
            new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());

    frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
    frameLayout.addView(adView, adViewLayoutParams);

    this.setContentView(frameLayout, frameLayoutLayoutParams);
}

Also have a look at a screenshot from eclipse for details. 还可以查看eclipse的屏幕截图以获取详细信息。

Am I right when I assert that all of those 25 examples that I have found are deprecated due to a new version? 我断言我发现的所有25个示例都由于新版本而被弃用了,对吗?

These methods are from the "old" admob API that will be deprecated very soon. 这些方法来自“旧” admob API,该API将很快弃用。 Now admob is integrated with Google Play Game Services. 现在admob已与Google Play游戏服务集成。 So you need to remove the admob library, and use the new API: https://developers.google.com/mobile-ads-sdk/docs/?hl=es 因此,您需要删除admob库,并使用新的API: https : //developers.google.com/mobile-ads-sdk/docs/?hl=es

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

相关问题 Android Google Play服务广告未展示 - Android Google Play Services Ads not showing Google Play服务移动广告需要AdMob帐户 - Google play services mobile ads requires AdMob account 如何更改Google Play服务中插页式广告的尺寸? - How can i change size of interstitial ads in google play services? 通过Android-Studio和“新” Google Play服务SDK实施Google广告 - Implementing Google ads via Android-Studio and the 'New' Google Play Services SDK 更新到'com.google.android.gms:play-services-ads:17.1.2'后,Admob广告无法加载 - Admob Ads don't load after updating to 'com.google.android.gms:play-services-ads:17.1.2' 每当我添加google.android.gms:play-services-ads:18.1.0时,清单合并失败 - Manifest merged fail every time I add google.android.gms:play-services-ads:18.1.0 升级到'com.google.android.gms:play-services-ads:18.1.0'后Android编译错误 - Android compilation error after upgrading to 'com.google.android.gms:play-services-ads:18.1.0' Admob Google Play 服务。 显示插页式广告时出现空指针异常 - Admob Google Play services. null pointer exception when showing interstitial ads 我在哪里可以将google-play-services-ads.jar包含在我的项目中? - Where do i get google-play-services-ads.jar to include in my project? 无法解析 com.google.android.gms:play-services-ads:19.1.0 - Could not resolve com.google.android.gms:play-services-ads:19.1.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM