I’ve been following the instructions from the AdMob site (here:https://developers.google.com/mobile-ads-sdk/docs/?hl=en) and I’m still unable to get the ads to work, but there doesn’t seem to be anything wrong.
Here’s my Layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:soundEffectsEnabled="true"
android:id="@+id/mainLayout"
android:background="@drawable/bg_maple"
>
[...]
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="my real unit id from admob"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, my real device id"
ads:loadAdOnCreate="true"/>
[...]
And in my Activity:
public class Banner extends Activity {
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Create the adView
adView = new AdView(this, AdSize.BANNER, "my real unit id from admob");
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
RelativeLayout layout = (RelativeLayout)findViewById(R.id.mainLayout);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
adRequest.addTestDevice("Here I have my device ID");
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
Any help is appreciated, I’m stuck and don’t seem to be able to see what’s wrong at the moment.
Note: my unit id, and the device id are both added correctly to the code.
you are using two separate AdView, the first from your xml and the second from code. please try to change your code