我已完成游戏,并想在游戏中添加Admob广告。
中的所有说明操作并且它工作得非常好,并且广告正确显示,我只是想确保我做得很好并且adomb的版本是正确的,并且知道是否已准备好签名并上传到游戏商店:
这是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,或者我可以使用广告发布我的游戏而无需google.service.json文件
答案 0 :(得分:0)
您不需要添加该文件以在您的应用中展示广告。其他更有用的目的需要该文件...例如在数据库等...