integrate admob

Costas

Administrator
Staff member
references :
http://apps.admob.com
<a href="https://developers.google.com/mobile-ads-sdk/docs/" target="_blank">https://developers.google.com/mobile-ads-sdk/docs/
</a>https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#play


*1*
From SDK Manager.exe download the 'Google Play Services' by Extras
snap870.png

*2*
will download the library + samples
C:\androidSDK\extras\google\google_play_services

import google_play_services to eclipse! (be sure that copy to workspace is checked)
snap873.png


snap875.png


*3*
Make the reference
snap872.png


*4*
add to application tag the :

JavaScript:
    <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"/>

make sure you add the needed permissions :

JavaScript:
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

*5*
At the activity you like to appear the ad, on XML should be a linearlayout :

JavaScript:
    <LinearLayout
        android:id="@+id/linearLayoutAD"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    </LinearLayout>

public variables :

JavaScript:
  /** The view to show the ad. */
  private AdView adView;

  /* Your ad unit id. Replace with your actual ad unit id. */
  private static final String AD_UNIT_ID = "INSERT_YOUR_AD_UNIT_ID_HERE";

onCreate add :

JavaScript:
		///////////
		// Create an ad.
		adView = new AdView(this);
		adView.setAdSize(AdSize.BANNER);
		adView.setAdUnitId(AD_UNIT_ID);

		// Add the AdView to the view hierarchy. The view will have no size
		// until the ad is loaded.
		LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayoutAD);
		layout.addView(adView);

		// Create an ad request. Check logcat output for the hashed device ID to
		// get test ads on a physical device.
		AdRequest adRequest = new AdRequest.Builder()
		.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
		.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
		.build();

		// Start loading the ad in the background.
		adView.loadAd(adRequest);
		/////////

at logcat you will get :
The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.

https://developers.google.com/mobile-ads-sdk/kb/#resourcesnotfound
 
Top