title: checking the availability of Google Play services on a device
body: <p>i am trying to check the availability of Google Play services on a device. but the app is crashing on start up. the app runs without the servicesOK() method, and i have imported the google play services into my project.. i'm not sure, or understand, why the app is crashing. </p>
  
  <p>here is my MainActivity.java (the only code in the app so far):</p>
  
  <pre><code>package com.example.gmapsapp;
  
  import com.google.android.gms.common.ConnectionResult;
  import com.google.android.gms.common.GooglePlayServicesUtil;
  import com.google.android.gms.maps.GoogleMap;
  
  import android.app.Activity;
  import android.app.Dialog;
  import android.os.Bundle;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
  private static final int GPS_EERRORDIALOG_REQUEST = 9001;
  GoogleMap mMap;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      if(servicesOK()){
                Toast.makeText(this,  "message", Toast.LENGTH_SHORT).show();
      }
  
      setContentView(R.layout.activity_main);
  }
  
  public boolean servicesOK(){
  
      int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
  
      if(isAvailable == ConnectionResult.SUCCESS){
          return true;
      }
      else if(GooglePlayServicesUtil.isUserRecoverableError(isAvailable)){
          Dialog dialog = 
                  GooglePlayServicesUtil.getErrorDialog(isAvailable, 
                           this, GPS_EERRORDIALOG_REQUEST);
          dialog.show();
      }
      else {
          Toast.makeText(this,  "Cannot Connect to to Google Play services", Toast.LENGTH_SHORT).show();
      }
      return false;
  }
  </code></pre>
  
  <p>}</p>