List of usage examples for android.location LocationManager isProviderEnabled
public boolean isProviderEnabled(String provider)
From source file:Main.java
/** * Method to register location updates with a desired location provider. If the requested * provider is not available on the device, the app displays a Toast with a message referenced * by a resource id.//from ww w . j av a 2 s.c o m * * @param provider Name of the requested provider. * @param errorResId Resource id for the string message to be displayed if the provider does * not exist on the device. * @return A previously returned {@link android.location.Location} from the requested provider, * if exists. */ public static Location requestUpdatesFromProvider(LocationManager locationManager, LocationListener locationListener, final String provider, final int errorResId) { Location location = null; if (locationManager.isProviderEnabled(provider)) { locationManager.requestLocationUpdates(provider, RUN_ONCE, RUN_ONCE, locationListener); location = locationManager.getLastKnownLocation(provider); } return location; }
From source file:Main.java
public static boolean checkLocationService(Context context) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); boolean gps_enabled = false; boolean network_enabled = false; try {/*from w w w . j a v a 2s.co m*/ gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { } try { network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception ex) { } return gps_enabled; }
From source file:Main.java
public static void isGPSActivated(final Context context) { LocationManager lm = null; boolean gpsEnabled = false; if (lm == null) lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); try {//from w ww . java 2 s . co m gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { } if (!gpsEnabled) { AlertDialog.Builder dialog = new AlertDialog.Builder(context); dialog.setCancelable(false); dialog.show(); } }
From source file:com.djit.mixfader.sample.BaseActivity.java
/** * Check if the user needs to enable the location. * <p/>/*from w w w . j a v a2s . co m*/ * Since Android Marshmallow, the location is required to scan for bluetooth devices. * * @return Return true is the location need to be enable, false otherwise. */ private static boolean needToEnableLocation(final Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return false; } else { final LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE); return !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } }
From source file:com.nextgis.maplibui.util.NotificationHelper.java
public static void showLocationInfo(final Context context) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (!preferences.getBoolean(SettingsConstantsUI.KEY_PREF_SHOW_GEO_DIALOG, true)) return;/*from ww w.jav a2 s . c o m*/ LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); final boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); final boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled || !isNetworkEnabled) { String title, info; if (!isGPSEnabled && !isNetworkEnabled) { title = context.getString(R.string.location_disabled); info = context.getString(R.string.location_disabled_msg); } else { String network = "", gps = ""; if (!isNetworkEnabled) network = "\r\n- " + context.getString(R.string.location_network); if (!isGPSEnabled) gps = "\r\n- " + context.getString(R.string.location_gps); title = context.getString(R.string.location_accuracy); info = context.getString(R.string.location_inaccuracy) + network + gps; } if (context instanceof Activity) showLocationDialog(context, title, info); else showLocationNotification(context, title, info); } }
From source file:com.prey.actions.location.LocationUtil.java
public static HttpDataService dataLocation(Context ctx) { HttpDataService data = null;// w w w. j a va2 s. com try { LocationManager mlocManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); boolean isGpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = mlocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); PreyLogger.d("gps status:" + isGpsEnabled); PreyLogger.d("net status:" + isNetworkEnabled); PreyLocation location = null; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { if (isGpsEnabled || isNetworkEnabled) { String method = getMethod(isGpsEnabled, isNetworkEnabled); PreyLocation locationPlay = null; int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx); if (ConnectionResult.SUCCESS == resultCode) { location = getPreyLocationPlayService(ctx, method); } } } else { PreyLogger.d("ask for permission location"); } if (location == null) location = getDataLocationWifi(ctx); if (location != null) { PreyLogger.d("locationData:" + location.getLat() + " " + location.getLng() + " " + location.getAccuracy()); data = convertData(location); } else { sendNotify(ctx, "Error"); } } catch (Exception e) { sendNotify(ctx, "Error"); } return data; }
From source file:Main.java
/** * Returns whether location services are currently active in the specified context. Location * services are active if both GPS and network location services are enabled. * @param context the context from which to check * @return true if there location services are on, otherwise false *//* www .j av a 2s . c o m*/ public static boolean isLocationServicesOn(Context context) { LocationManager lm = (LocationManager) context.getApplicationContext() .getSystemService(Context.LOCATION_SERVICE); boolean gpsEnabled = false; boolean networkEnabled = false; // check whether GPS and network providers are enabled try { gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception e) { } try { networkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception e) { } // only show dialog if location services are not enabled return (gpsEnabled || networkEnabled); }
From source file:com.code19.library.SystemUtils.java
/** * <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> *///w ww .j a v a 2s . c om public static boolean isGpsEnabled(Context context) { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return lm.isProviderEnabled(LocationManager.GPS_PROVIDER); }
From source file:com.tagaugmentedreality.utilties.Utilities.java
public static boolean locationProviderStatus(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { return true; } // end if/*from w ww.j a va 2s . co m*/ else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { return true; } // end if else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { return true; } // end else if else { return false; } // end else }
From source file:com.forrestguice.suntimeswidget.getfix.GetFixHelper.java
public static boolean isGPSProviderEnabled(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); }