List of usage examples for android.content Context LOCATION_SERVICE
String LOCATION_SERVICE
To view the source code for android.content Context LOCATION_SERVICE.
Click Source Link
From source file:Main.java
public static boolean isGpsOn(Context context) { boolean result = false; final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); try {//from w w w . j a v a2 s . co m if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { result = true; } } catch (IllegalArgumentException e) { Log.d("GPS Helper", "Looks like we do not have gps on the device"); } return result; }
From source file:Main.java
public static boolean deviceSupportGPS(Context context) { boolean result = false; final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> allProviders = manager.getAllProviders(); if (allProviders.contains(LocationManager.GPS_PROVIDER)) { result = true;//from ww w. j a v a 2 s . co m } return result; }
From source file:Main.java
public static Location getLocation(Context context) { try {/* www. ja va 2 s.c om*/ LocationManager locMan = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Location location = locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null) { location = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } return location; } catch (Exception e) { } return null; }
From source file:Main.java
/** * * @param activity/*from w w w .j ava 2s .c o m*/ * @return */ public static boolean isGPSEnabled(Activity activity) { final LocationManager manager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE); if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { return true; } return false; }
From source file:Main.java
public static double[] getLastKnownLocation(Activity a) { LocationManager locationManager = (LocationManager) a.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = locationManager.getBestProvider(criteria, true); System.out.println("provider: " + provider); Location location = locationManager.getLastKnownLocation(provider); return new double[] { location.getLatitude(), location.getLongitude() }; }
From source file:Main.java
public static Location getLastKnownLocation(Context context) { LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = manager.getProviders(true); for (String provider : providers) { Location location = manager.getLastKnownLocation(provider); if (location != null) { return location; }// w w w . jav a2 s. c o m } // At this point we've done all we can and no location is returned return null; }
From source file:Main.java
/** * Is gPS enabled./* w ww.j a va2s. co m*/ * * @param context the context * @return the boolean */ public static boolean isGPSEnabled(Context context) { final LocationManager locationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); }
From source file:Main.java
/** * Check Network provider is enabled for location update * * @param context/*from ww w . ja v a 2 s . c om*/ * @return if network provider enabled */ public static boolean isNetworkProviderEnabled(Context context) { final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); }
From source file:Main.java
/** * This method checks phone if it is able to get user's location * @param context/*from w w w. j a v a 2 s .c om*/ * @return */ public static boolean testLocationServices(Context context) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Location locationGPS = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location locationNet = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); boolean haveGPS = (locationGPS != null); boolean haveNet = (locationNet != null); return (haveGPS || haveNet); }
From source file:Main.java
public static void isGPSActivated(final Context context) { LocationManager lm = null;//from w w w . j a v a2 s .co m boolean gpsEnabled = false; if (lm == null) lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); try { gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { } if (!gpsEnabled) { AlertDialog.Builder dialog = new AlertDialog.Builder(context); dialog.setCancelable(false); dialog.show(); } }