0
我已經完成了我的遊戲並希望將Admob廣告添加到遊戲中。Libgdx將admob添加到遊戲的最後階段
所有的指令和它的工作非常好,廣告是正常顯示的,我只是想確保我做的一切良好,adomb的版本是正確的,並知道如果準備簽署並上傳到Play商店:
這裏是在AndroidLuncher代碼:
public class AndroidLauncher extends AndroidApplication implements AdHandler {
private static final String TAG="AndroidLauncher";
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);
RelativeLayout layout=new RelativeLayout(this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
View gameview= initializeForView(new Fruits(this),config);
layout.addView(gameview);
adView=new AdView(this);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i(TAG, "ad Loaded");
}
});
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("ca-app-pub-7056408444444289676685175896");
AdRequest.Builder builder=new AdRequest.Builder();
RelativeLayout.LayoutParams adParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
adView.loadAd(builder.build());
layout.addView(adView, adParams);
setContentView(layout);
//initialize(new Fruits(), config);
}
@Override
public void showAds(boolean show) {
handler.sendEmptyMessage(show ?SHOW_ADS:HIDE_ADS);
}
}
,這是manifest.xml文件:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity
android:name="com.mygdx.game.AndroidLauncher"
android:label="@string/app_name"
android:screenOrientation="landscape"
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"/>
</application>
</manifest>
這裏是build.grade:
ext {
appName = "Fruits Eater"
gdxVersion = '1.7.2'
roboVMVersion = '1.12.0'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.7.0'
admobVersion='9.2.0'
}
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
compile "com.google.android.gms:play-services-ads:$admobVersion"
}
而且我想知道如果我需要添加google.service.json,或者我可以發表我的遊戲廣告,而不需要谷歌的.service.json文件