package com.phonegap.plugins;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.location.LocationManager;
import android.content.Context;
/*
 * thx to http://stackoverflow.com/questions/843675/how-do-i-find-out-if-the-gps-of-an-android-device-is-enabled
 */
public class ServiceCheck extends CordovaPlugin{
	@Override
	public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
		if (action.equals("checkAvailabilityServices")){
			this.checkAvailabilityServices(callbackContext);
			return true;
		}
		return false;
	}

	private void checkAvailabilityServices(CallbackContext callbackContext){
		Context context = this.cordova.getActivity().getApplicationContext();
    final LocationManager manager = (LocationManager) context.getSystemService( Context.LOCATION_SERVICE );
    if ( manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
			callbackContext.success();
    }else{
			callbackContext.error(0);
		}
  }
}

@@ -269,16 +269,134 @@
 ontext;%0A
+%0Aimport com.google.android.gms.common.ConnectionResult;%0Aimport com.google.android.gms.common.GooglePlayServicesUtil;%0A%0A
 /*%0A * th
@@ -801,16 +801,137 @@
 ue;%0A%09%09%7D%0A
+%09%09%0A%09%09if (action.equals(%22checkLocationSettings%22))%7B%0A%09%09%09this.checkLocationSettings(callbackContext);%0A%09%09%09return true;%0A%09%09%7D%0A%09%09%0A
 %09%09return
@@ -1016,16 +1016,19 @@
 ntext)%7B%0A
+%09%09%0A
 %09%09Contex
@@ -1091,20 +1091,521 @@
 text();%0A
-    
+%09%09int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);%0A%09%09%0A%09%09// Showing status%0A%09%09if(status==ConnectionResult.SUCCESS)%0A%09%09%09callbackContext.success();%0A%09%09else%7B%09%09%09%0A%09%09%09callbackContext.error(0);%0A%09%09%09//int requestCode = 10;%0A%09%09%09//Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);%0A%09       // dialog.show();%0A%09%09%7D%09%09%0A%09%7D%0A%09%0A%09private void checkLocationSettings(CallbackContext callbackContext)%7B%0A%09%09Context context = this.cordova.getActivity().getApplicationContext();%0A%09%09
 final Lo
@@ -1700,20 +1700,18 @@
 VICE );%0A
-    
+%09%09
 if ( man
@@ -1799,20 +1799,18 @@
 cess();%0A
-    
+%09%09
 %7Delse%7B%0A%09
@@ -1841,14 +1841,13 @@
 0);%0A%09%09%7D%0A
-  
+%09
 %7D%0A%7D%0A

add Google play service check function.