Saturday 25 January 2014

Multiple List View Example

Hello friends Today I will write a code for Multiple List View .

Please Proceed following steps :

STEP 1 : CREATE A PROJECT MultipleListView

STEP 2 : PUT FOLLOWING CODE IN MainActivity 


package com.ritesh.multiplelistview;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity implements OnItemClickListener  {
private ArrayAdapter<String> adaptern;
private String[] namelist = new String[] {"android","aman","bharat","banana","calc","come","dell","dhoom","ele",
"fork","fail","goyal","home","imagine","jama","kaman","lawan","mohit","mohan","noida","oman","police","qatar","rest",
"satya","truth","ugly","volume","work","wow","xmas","yeah","yes","zebra"};

private String[] name = new String[] {"#","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r",
"s","t","u","v","w","x","y","z"};
private ListView listmain;
private ArrayList<String> list_name=new ArrayList<String>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listside=(ListView)findViewById(R.id.listviewside);
listmain=(ListView)findViewById(R.id.listViewmain);

 
for (int i = 0; i < namelist.length; i++) {
list_name.add(namelist[i]);

}

ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, name);
listside.setAdapter(adapter);


adaptern=new ArrayAdapter<String>(MainActivity.this, R.layout.itemtext, list_name);
listmain.setAdapter(adaptern);

listside.setOnItemClickListener(this);
}

 @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
 list_name.clear();
 if ((name[arg2]).equals("#")) {
 for (int i = 0; i < namelist.length; i++) {
list_name.add(namelist[i]);
}
}
 else {
 
 for (int i = 0; i < namelist.length; i++) {
if((namelist[i].substring(0, 1)).equals(name[arg2])){
list_name.add(namelist[i]);
}
   }
  }
    adaptern.notifyDataSetChanged();
}

       }

STEP 3 : PUT THIS CODE IN activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android1:id="@+id/listViewmain"
        android1:layout_width="match_parent"
        android1:layout_height="wrap_content"
        android1:layout_alignParentLeft="true"
        android1:layout_alignParentTop="true"
        android1:layout_toLeftOf="@+id/listviewside" >

    </ListView>
    
    
     <ListView
        android1:id="@+id/listviewside"
        android1:layout_width="40dp"
        android1:layout_height="wrap_content"
        android1:layout_alignParentRight="true"
      
        android1:layout_alignParentTop="true" >
    </ListView>

</RelativeLayout>

STEP 4 : PUT THIS CODE IN itemtext.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:text="TextView"
     android:textColor="#00FF00"
     android:gravity="center_vertical"
     android:paddingLeft="20dp"
     android:background="@android:color/black"
    android:textAppearance="?android:attr/textAppearanceMedium" />


STEP 5 : PUT THIS CODE IN manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ritesh.multiplelistview"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.ritesh.multiplelistview.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>




Thursday 23 January 2014

List View with Search Example





Hello friends Today I will write a code for list view with search step by step :

STEP 1:  Write this code in MainActivity 

package com.ritesh.listviewsearch;

import java.util.ArrayList;
import java.util.HashMap;

import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity implements TextWatcher, OnItemClickListener {
private ArrayList<HashMap<String,String>> listhash;
private ArrayList<HashMap<String,String>> listhash_second;
private ListView listset;
private EditText edittext;
private ListViewAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edittext=(EditText)findViewById(R.id.editText_search);
listset=(ListView)findViewById(R.id.list);
listhash=new ArrayList<HashMap<String,String>>();
listhash_second=new ArrayList<HashMap<String,String>>();
//Insert Data
for (int i = 0; i < 20; i++) {
HashMap<String, String> map=new HashMap<String, String>();
map.put("name", i+"ritesh");
map.put("phone", "99999999:"+i);
   listhash.add(map);
   listhash_second.add(map);
}
for (int i = 0; i < 20; i++) {
HashMap<String, String> map=new HashMap<String, String>();
map.put("name", i+"android");
map.put("phone", "9656599:"+i);
   listhash.add(map);
   listhash_second.add(map);
}
adapter=new ListViewAdapter(MainActivity.this,listhash);
listset.setAdapter(adapter);
listset.setOnItemClickListener(this);
edittext.addTextChangedListener(this);
}

@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub

}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub

}

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub

  int textlength = arg3+1;

  String textstring =String.valueOf(arg0);
   
 Log.d("textlength", ""+textlength);
 Log.d("textstring", ""+textstring);
 listhash.clear();
for (int i = 0; i < listhash_second.size(); i++) {
String name = listhash_second.get(i).get("name");

if (textlength <= name.length()) {

if(name.contains(edittext.getText().toString()))
{
listhash.add(listhash_second.get(i));
}  }
  }
adapter.notifyDataSetChanged();



}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, listhash.get(arg2).get("name"), Toast.LENGTH_LONG).show();
}
}



STEP 2:  Write this code in ListViewAdapter

package com.ritesh.listviewsearch;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter{
LayoutInflater layoutinflater;
ArrayList<HashMap<String, String>> listhash;
Activity activity;
private ViewHolder holder;

public ListViewAdapter(Activity activity,
ArrayList<HashMap<String, String>> listhash) {
// TODO Auto-generated constructor stub
this.listhash=listhash;
this.activity=activity;
this.layoutinflater=LayoutInflater.from(activity);
}

private class ViewHolder {
public TextView tvname;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return listhash.size();
}

@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}

@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

if (convertView == null) {
convertView = layoutinflater.inflate(R.layout.list_item,
null);
holder = new ViewHolder();
holder.tvname = (TextView) convertView
.findViewById(R.id.text_name);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvname.setText(listhash.get(position).get("name"));


return convertView;
}


}

STEP 3 : Write this code in activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/editText_search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_marginRight="25dp"
        android:layout_alignParentTop="true"
        android:hint="Search Name"
        android:layout_centerHorizontal="true"
        android:ems="10" >

       
    </EditText>

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText_search"
        android:layout_centerHorizontal="true"
        
         android:cacheColorHint="@android:color/transparent" 
        android:layout_marginTop="4dp" >
    </ListView>
   
</RelativeLayout>


STEP 4 : Write this code in list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="56dp"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>


STEP 5 : Write this code in manifest file




<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ritesh.listviewsearch"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.ritesh.listviewsearch.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Run the Project....





Tuesday 21 January 2014

Android Upload Image to Php Server

Today I will write a code for upload image to php server in android in string .You need to decode string file in php server using Base64 .

Step 1: Create Project  UploadImageToServer .

Step 2 : Write Code in MainActivity 

package com.ritesh.uploadimage;

import java.io.ByteArrayOutputStream;

import org.json.JSONObject;

import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity {
public static final int RESULT_LOAD_IMAGE = 10;
private static final int CAMERA_REQUEST = 1888;
String imagestring="";
Bitmap photo;
ImageView setimage;
Utils utils;
String message;
ProgressDialog pDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button ButtonCamera=(Button)findViewById(R.id.buttonCamera);
Button buttonGallery=(Button)findViewById(R.id.buttongallery);

Button ButtonUpload=(Button)findViewById(R.id.buttonupload);
setimage=(ImageView)findViewById(R.id.image);
ButtonCamera.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//Capture image from camera
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(intent, CAMERA_REQUEST);
}
});
buttonGallery.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//Capture image from gallery
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
ButtonUpload.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
utils=new Utils();
new UploadImage().execute();
}
});
}





@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {

Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };

Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();


   photo=Utils.decodeSampledBitmapFromPath(picturePath, 400, 400);

loadImage();

 } else  if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK)  {

 photo = (Bitmap) data.getExtras().get("data");


loadImage();




}}


       private void loadImage() {
     // TODO Auto-generated method stub
 
      Log.e("addimg", "imgggg");
      //resize image according to your need and replace value of 200 and 200
      Bitmap btm00 = Utils.getResizedBitmap(photo, 200, 200);
      setimage.setImageBitmap(btm00);
       
          ByteArrayOutputStream bao = new ByteArrayOutputStream();
       
          photo.compress(Bitmap.CompressFormat.JPEG, 90, bao);
          byte[] ba = bao.toByteArray();
          imagestring = Base64.encodeBytes(ba);
 }
       class UploadImage extends AsyncTask<String, String, String>{
       
      @Override
   protected void onPreExecute() {
    // TODO Auto-generated method stub
    super.onPreExecute();
    ProgressDialog pDialog=new ProgressDialog(MainActivity.this);
    pDialog.setMessage("Sending..");
    pDialog.setCancelable(true);
    pDialog.show();
   
   
   }

      @Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
try {
JSONObject json=utils.SendToServer(imagestring);
message=json.getString("MSG");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}


return null;
   }
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub

pDialog.dismiss();
Toast.makeText(MainActivity.this, "Hello :"+message, Toast.LENGTH_LONG).show();
}
               }
       
}



Step 3: Write this code in JSONParser

package com.ritesh.uploadimage;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {
private InputStream is = null;
    private JSONObject jObj = null;
    private String json = "";
 
    // constructor
    public JSONParser() {
 
    }
    
    public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {

    // Making HTTP request
    try {
    // defaultHttpClient
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));

    HttpResponse httpResponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();
    is = httpEntity.getContent();

    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    } catch (ClientProtocolException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }

    try {
    BufferedReader reader = new BufferedReader(new InputStreamReader(
    is, "utf-8"), 8);
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");
    }
    is.close();
    json = sb.toString();
    Log.e("JSON", json);
    } catch (Exception e) {
    Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
    jObj = new JSONObject(json);
    } catch (JSONException e) {
    Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

    }
    
    public JSONObject getJSONFromUrl(String url) throws IllegalStateException, IOException, JSONException {
 
// Making HTTP request
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

BufferedReader reader = new BufferedReader(new InputStreamReader(is,
"utf-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();

// try parse the string to a JSON object
jObj = new JSONObject(json);

// return JSON String
return jObj;
 
    }
}


Step 4: Write this Code in Utils

package com.ritesh.uploadimage;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;

public class Utils {
public static Bitmap decodeSampledBitmapFromPath(String pathName, int reqWidth, int reqHeight) {
   // First decode with inJustDecodeBounds=true to check dimensions
   final BitmapFactory.Options options = new BitmapFactory.Options();
   options.inJustDecodeBounds = true;
   BitmapFactory.decodeFile(pathName, options);

   // Calculate inSampleSize
   options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

   // Decode bitmap with inSampleSize set
   options.inJustDecodeBounds = false;
   return BitmapFactory.decodeFile(pathName, options);
}
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
   // Raw height and width of image
   final int height = options.outHeight;
   final int width = options.outWidth;
   int inSampleSize = 1;
   if (height > reqHeight || width > reqWidth) {
       if (width > height) {
           inSampleSize = Math.round((float)height / (float)reqHeight);
       } else {
           inSampleSize = Math.round((float)width / (float)reqWidth);
       }
   }
   return inSampleSize;
}
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// RECREATE THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);
return resizedBitmap;
}
public JSONObject SendToServer(String imagestring) {
JSONParser jsonParser=new JSONParser();
// TODO Auto-generated method stub
List<NameValuePair> params = new ArrayList<NameValuePair>();
//Change your params (image)
 params.add(new BasicNameValuePair("image", imagestring));
//Change your server link and replace to this one (www.exampleupladurl.com)
 JSONObject json = jsonParser.getJSONFromUrl("www.exampleupladurl.com", params);
 return json;
}
}

Step 5: Write this Code in Manifest file 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ritesh.uploadimage"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.ritesh.uploadimage.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


Step 5: Downlaod Base64.java and insert in to your project  .

Run the Project







Saturday 18 January 2014

Implementing Admob in Android App



Implementing Admob in Android App


Today I will write a code for implement admob in android app step by step..

Step 1 :  Create New App AdmobDemob in eclipse . 

Step 2 : Add google_play_service_library(Explained in step 2.1  ) to your project now no need to add admob library

Step 2.1 : Go to sdk folder >google >google_play_service>libproject >google_play_service_library(this is the path of google_play_service_libary). Now import this library project in your eclipse and add refrence library to your AdmobDemo Project (How to add Library Project explained in Step 2.2)

Step 2.2 :Right Click on your project(AdmobDemo ) go to property >android >Add >Select google_play_service_library click Ok then apply then Ok .

Step 3: put this code in MainActivity .

package com.ritesh.admobdemo;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InitAction();
}

private void InitAction() {
// TODO Auto-generated method stub
 AdView adView = (AdView)this.findViewById(R.id.adView);
   AdRequest adRequest = new AdRequest.Builder().build();
 
   adView.loadAd(adRequest);
}


}


Step 4 :  Add this Code in your activity_main  xml 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:background="@android:color/darker_gray"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
  <com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="a15264bfhdbd4fsd"
                         android:layout_gravity="center_horizontal|center_vertical"
                         
                         ads:adSize="BANNER"/>
</LinearLayout>

NOTE : Change your adunitId  in xml file  and replace to this one (a15264bfhdbd4fsd)


Step 5 : Add this code in your manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ritesh.admobdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
         <meta-data android:name="com.google.android.gms.version" android:value="4030500" />
        <activity
            android:name="com.ritesh.admobdemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

Run The Project