Music Monkey
Music Monkey

Reputation: 340

Upgrading AdMob SDK and fail on load() method

I've been working to update to the new AdMob that requires google services to function. I'm using this code in onCreate()

AdView adView = (AdView)this.findViewById(R.id.adView);
//AdRequest
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
adView.loadAd(adRequest);
Log.d("ADMOB", "Successfully loaded");

and am using this code in XML

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal"
ads:adSize="SMART_BANNER"
ads:adUnitId="ADMOB_ID"/>

However, the adMob ad does not display. The try/catch block fails here:

adView.loadAd(adRequest);

The AndroidManifest code looks like this:

<meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

    <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

What am I missing?

Upvotes: 0

Views: 243

Answers (1)

Farouk Touzi
Farouk Touzi

Reputation: 3456

Referring to the AdMob Android Guides I quote

Next, create the onActivityCreated method. This is where you'll build and load the AdRequest. Reference the AdView, then build and load the AdRequest.

So, you must implement it like following :

@Override
public void onActivityCreated(Bundle bundle) 
{
  super.onActivityCreated(bundle);
  AdView mAdView = (AdView) getView().findViewById(R.id.adView);
  AdRequest adRequest = new AdRequest.Builder().build();
  mAdView.loadAd(adRequest);
}

Upvotes: 1

Related Questions