Mar 3, 2014

How to insert adMob in my android app?



Step 1

You need a adMob account.

You are going to adMob page and create an account.



If already have an account, need a log in.

You can be seen to below image, if you log in first time.

This is important!!!

'Country' is choose your country.

'Account Type' choose your type.

'Business Name' typing your company name or your name.

And choose received pay type. ACH/Wire or PayPal.

If you choose ACH/Wire, you receive when earn over $100 but you choose PayPal, you receive when earn over $20.

If you Korean, you can reference 'Bank SWIFT Code'  to this site.  




Step 2

You log in adMob and click to' Add Site/App' in 'Sites&Apps' tab.


And choose Android App ,you can be seen to below image.



Need a fill.

'App name' is your app name.

'Android package URL' is your app market's URL. If you don't have a market URL , just typing http://

'Category' is app's category.

'App descriptions' is your app description.

'Other Google Ads' is choose ad method. maybe first is good method.

And  click to 'Continue' after fill a secret number.


Step 3

You download SDK.

Unzip SDK and Open your eclipse project.

Copy 'GoogleAdMobAdsSdk-6.4.1.JAR' in zip file to android project libs folder.



And Coding your project.

JAVA file

  1. import com.google.ads.AdRequest;
  2. import com.google.ads.AdView;
  3. ....
  4. public class MainActivity extends Activity  implements OnClickListener,OnItemSelectedListener  {
  5.    
  6.     AdView adView;
  7.    
  8.     .............
  9.    
  10.     @Override
  11.     public void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.activity_main);
  14.    
  15.        
  16.         AdView adView = (AdView)this.findViewById(R.id.adView);
  17.         adView.loadAd(new AdRequest());
  18.         .............
  19.     }
  20. ................
  21. }
XML file

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent"
  5.    android:orientation="vertical"
  6.    xmlns:tools="http://schemas.android.com/tools"
  7.    tools:context=".MainActivity" >
  8.    
  9.     <com.google.ads.AdView
  10.        android:id="@+id/adView"
  11.        android:layout_width="wrap_content"
  12.        android:layout_height="wrap_content"
  13.        ads:adUnitId="your KEY"
  14.        ads:adSize="SMART_BANNER"
  15.        ads:loadAdOnCreate="true"/>
You getting 'adUnitId' in adMob page.(sites& apps tab->your app name click)



Copy 'publisher ID' and paste to 'adUnitId'.

AndroidManifest.xml

  1. .........
  2. <uses-permission android:name="android.permission.INTERNET"/>
  3. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  4.     <application
  5.        ..........
  6.       >
  7.          .........
  8.         <activity
  9.            android:name="com.google.ads.AdActivity"
  10. android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
  11.        
  12.        </application>
  13. .....


This image is  running app. 

You can be seen to add adMob in your app.






No comments:

Post a Comment