We know that, Google Map Android API V2 requires Google Play Services to work and so it is always a best practice to check whether the Google Play Services are installed in the device on starting up the Google Map application.
In this article, we will create an application which checks whether Google Play Services are available in the hosting device on starting up the application. If the service is not available, a dialog window appears to prompt user to install Google Play Services in the device.
This application is developed in Eclipse(4.2.1) with ADT plugin(21.0.0) and Android SDK(21.0.0).
1. Download and configure Google Play Services Library in Eclipse
Please follow the given below link to setup Google Play Service library in Eclipse.
http://developer.android.com/google/play-services/setup.html
2. Create a new Android application project
3. Configure the project
4. Design application launcher icon
5. Create a blank activity
6. Enter MainActivity details
7. Add Google Play Services Library to this project
8. Update the layout file res/layout/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" tools:context=".MainActivity"> <TextView android:id="@+id/tv_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> </RelativeLayout>
9. Update the file src/in/wptrafficanalyzer/checkgoogleplayservices/MainActivity.java
package in.wptrafficanalyzer.checkgoogleplayservices; import android.app.Activity; import android.app.Dialog; import android.os.Bundle; import android.view.Menu; import android.widget.TextView; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; public class MainActivity extends Activity { @Override protected void onResume() { super.onResume(); // Getting reference to TextView to show the status TextView tvStatus = (TextView)findViewById(R.id.tv_status); // Getting status int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext()); // Showing status if(status==ConnectionResult.SUCCESS) tvStatus.setText("Google Play Services are available"); else{ tvStatus.setText("Google Play Services are not available"); int requestCode = 10; Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); dialog.show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
10. Executing the application
11. Download the source code


I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in
You can hire me on hourly basis or on project basis for Android applications development.
For hiring me, please mail your requirements to info@wptrafficanalyzer.in.
My other blogs
store4js.blogspot.com
hi. i’ve made an app using maps api v2 and when i start that app, it crashes if the gps is off. can you show how to check for that and enable it so the app doesn’t crash?
Hi, I use your code and works perfeclty for me.
Its checking but not install the google play services