Hi Friends Today we are going to see about how to add admob in our Android Application.
Ad Mob released Ad Mob SDK v6.0.1 for android a few days ago.
Download the latest Google Admob Ads SDK from following link
https://developers.google.com/mobile-ads-sdk/download
and paste it in your project libs folder.
Your Manifest file should contain the following permissions
And the following activity
<activity android:name="com.google.ads.AdActivity"/>
Your Activity will be look like something below.
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import com.google.ads.*;
public class AdmobExample extends Activity {
/** Called when the activity is first created. */
private AdView myAdView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myAdView = new AdView(this, AdSize.BANNER, "youradmob id. ");
//get layoutView
LinearLayout rootView = (LinearLayout)this.findViewById(R.id.rootViewGroup);
LinearLayout.LayoutParams layoutParams = new LayoutParams(480, 75);
rootView.addView(myAdView, 0, layoutParams);
AdRequest re = new AdRequest();
re.setGender(AdRequest.Gender.FEMALE);
myAdView.loadAd(re);
}
}
Your xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
>
<LinearLayout android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:id="@+id/rootViewGroup"
android:layout_height="wrap_content" >
</LinearLayout>
</RelativeLayout>
Ad Mob released Ad Mob SDK v6.0.1 for android a few days ago.
Download the latest Google Admob Ads SDK from following link
https://developers.google.com/mobile-ads-sdk/download
and paste it in your project libs folder.
Your Manifest file should contain the following permissions
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
And the following activity
<activity android:name="com.google.ads.AdActivity"/>
Your Activity will be look like something below.
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import com.google.ads.*;
public class AdmobExample extends Activity {
/** Called when the activity is first created. */
private AdView myAdView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myAdView = new AdView(this, AdSize.BANNER, "youradmob id. ");
//get layoutView
LinearLayout rootView = (LinearLayout)this.findViewById(R.id.rootViewGroup);
LinearLayout.LayoutParams layoutParams = new LayoutParams(480, 75);
rootView.addView(myAdView, 0, layoutParams);
AdRequest re = new AdRequest();
re.setGender(AdRequest.Gender.FEMALE);
myAdView.loadAd(re);
}
}
Your xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
>
<LinearLayout android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:id="@+id/rootViewGroup"
android:layout_height="wrap_content" >
</LinearLayout>
</RelativeLayout>
1 comment:
Hello, i am trying to develop an android screen capture application in the background every minute but I'm stuck I did not find the solution for screen capture,
you can help me please!!!
Merci
Post a Comment