I am using LibGDX 0.9.9 and Admob 6.4.1. I set up banner ads to appear in the top right corner of my app. However when I load up my app I can't see the banner. Although when I press where the banner should be it acts like normal and starts to appear. This happens both in testing mode and real mode. Here is my code:
public class MainActivity extends AndroidApplication {
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
cfg.useAccelerometer = false;
cfg.useCompass = false;
RelativeLayout layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
View gameView = initializeForView(new Game(), false);
// Create and setup the AdMob view
adView = new AdView(this);
adView.setAdUnitId("SECRET ID");
adView.setAdSize(AdSize.BANNER);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // Emulator
.addTestDevice("MY DEVICE ID") // My Nexus test
.build();
adView.loadAd(adRequest);
layout.addView(gameView);
// Add the AdMob view
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(adView, adParams);
setContentView(layout);
}
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
and the Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.keep.hopping"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<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"/>
<application
android:icon="@drawable/jumper"
android:label="Keep Hopping" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity
android:name="com.keep.hopping.MainActivity"
android:label="Keep Hopping"
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>
Anyone have any ideas as to why this weird behaviour is happening?
here it is the fix for integration of AdMob6.4.1 with libgdx, I put some lines of code:
this is the main.xml
the banner should load now.
Happy Coding!
Your problem could be that your 1st ad is hidden. If you waited 60 seconds and then your Adview appeared, you can fix it by only adding the AdView to the layout once your first ad loads by using an AdListener:
Hope this solves your headache!
Lunatikul's answer worked for me, but the important part for me was the padding:
I actually implemented it programmatically like this:
Hope this helps!
In my case the problem was solved simply by setting the background of the adview:
you can use any other color.