AdMob的libGDX与谷歌播放服务 [英] AdMob libGDX with Google Play services

查看:148
本文介绍了AdMob的libGDX与谷歌播放服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几天里谷歌是强制使用的谷歌游戏服务移动广告,AdMob的的Andr​​oid的下一个版本。林完全新的AdMob的,我试图在我的libGDX的android游戏,测试广告,但无法弄清楚如何做到这一点,因为我得到错误的荒谬量,无论我做什么。我已经看过其他的例子,但他们都对AdMob的6.4.1(或更早),这是目前被认为是旧的。我只是想要一个广告横幅在屏幕的底部,但无法弄清楚如何做到这一点。可能有人请张贴什么我的Andr​​oid MainActivity将需要还有什么我需要做的清单和XML。

Within the past few days google is forcing the use of the Google Play Services Mobile ads as the next version of android adMob. Im completely new to admob and am trying to test ads in my libGDX android game, but cant figure out how to do it because I get a rediculous amount of errors no matter what i do. I HAVE LOOKED AT OTHER EXAMPLES, but they are all for adMob 6.4.1(or earlier) which is now considered legacy. I just want an ad banner at the bottom of the screen but cant figure out how to do it. Could someone please post what my android MainActivity would need to be as well as anything I need to do to the manifest and xml.

这需要与libGDX和工作然而鉴于系统将与该合作

It NEEDS to work with libGDX and however the view system would cooperate with that

非常感谢你!

推荐答案

按照的上迁移到新的AdMob这里的官方指南。然后按照的AdMob在libgdx维基指南完成迁移。这真的很简单。

Follow the official guide on migrating to the new admob here. Then follow the admob in libgdx wiki guide to complete the migration. It's really simple.

你需要在你的MainActivity类的变化是:

The changes you'll need to make in your MainActivity class are:

更改线路:

 AdView adView = new AdView(this, AdSize.BANNER, "xxxxxxxx"); // Put in your secret key here
      adView.loadAd(new AdRequest());

AdView adView = new AdView(activity);
adView.setAdUnitId("xxxxxxx");
adView.setAdSize(AdSize.BANNER);
adView.loadAd(new AdRequest.Builder()
.build());

此外,因为您希望广告出现在屏幕的底部,修改adParams如下:

Additionally, since you want the ad to appear at the bottom of the screen, modify the adParams as follows:

RelativeLayout.LayoutParams adParams = 
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
        adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

而在你的清单文件,

And in your manifest file,

修改

<activity android:name="com.google.ads.AdActivity"/>

<activity android:name="com.google.android.gms.ads.AdActivity" 
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>`

<meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version"/>

您不必将广告视图在一个XML布局,因为它已经在MainActivity类进行编程。您也可以实现AdListener得到监听广告回调。

You don't need to define the ad view in an xml layout since it's already done programmatically in the MainActivity Class. You can also implement the AdListener to get listen for the Ad callbacks.

这篇关于AdMob的libGDX与谷歌播放服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆