Modifying the AndroidManifest.xml

import android code

If you create a new LibGDX project using the LibGDX Setup App and the settings I used in my project set up, your project set up after import in Eclipse should look something like this:


import android code

In this section we'll cover adding some code to our AndroidManifest.xml file. In the manifest file essential information is stored about our app. Information that it must have in order to run our app's code. When we import our new project that we created with the LibGDX Setup App the AndroidManifest.xml file is one of the files that is automatically generated for us.

Unmodifyed it should look something like this:


There are a couple of things we need to add to the manifest file in order to get our ads running:

  • Add a reference to use the Google Play Services
  • Add permissions so that our app will be allowed to access the internet in order to download the AdMob ads
  • Add an extra activity that will take care of displaying the banner ads

Adding a Google Play Services reference

In order to use the Google play services API's an Android Device needs to run at least Android 2.3 GingerBread which is API level 9. The AndroidManifest file contains information on the minimum sdk version that a device needs to have installed in order to run our app. In my case you can see that on line 8 the minimum SDK version is set to 8, but because Google Play Services requires API 9 or above this means that I will have to change the minSdkVersion to 9. This will mean that are running on Android version below 2.3 won't be able to run our app, but fortunately there are only very few device that don't run on version 2.3 or higher.

We've added the Google Play Services as a library to our project in part 1 of this tutorial.
We still need to create a reference to it in our AndroidManifest in order to use Google play services: Add the following tag as a child to the <application> element, for example just before the closing </application> tag.

Giving your app permission to access the internet

To give your app permission to access the internet add the following two lines of code, just above the <application> opening tag.

Declare an Activity for displaying Banner Ads

An activity is an application component that provides a screen for the user to interact with. When you look at the AndroidManifest file you'll see that there is one activity declared which will run when we start our application. This activity will run the AndroidLuancher file from our com.admob.android package which can be found in the source (src) folder of the Android module of our project.
For our Banner Ads we need te create a seperate Activity that will be placed on top of our Main Activity (our game) and that will take care of displaying the Banner Ads. After the closing </activity> tag of our first Activity paste the following line of code:

So now that we made the necessary changes to our AndroidManifest file we can start implementing some code to actually display our Ads. Let's start with Banner Ads.
If you want to check whether you added the code correctly this is what your Manifest file should look like: