2016-07-06 56 views
0

我已经完成了我的游戏并希望将Admob广告添加到游戏中。Libgdx将admob添加到游戏的最后阶段

我跟着Libgdx in 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文件

回答

0

你不需要添加文件显示在您的app.That文件的广告是需要其他更有效的目的......如数据库等...