1
\$\begingroup\$

I had finished my game and wanted to add Admob ads to the game.

I followed all the instructions in Admob in Libgdx

and It's working very well, and the ads are shown properly, I just wanna be sure that I did everything well and the version of the adomb is proper and know if the is ready to be signed and uploaded to the play store :

here is the code in the 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);
    }
}

and this is the manifest.xml file:

 <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>

and here is the 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"
    }

And I want to know if do I need to add google.service.json , or I can publish my game with ads without the need of google.service.json file.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.