List of usage examples for android.location LocationManager NETWORK_PROVIDER
String NETWORK_PROVIDER
To view the source code for android.location LocationManager NETWORK_PROVIDER.
Click Source Link
From source file:Main.java
public static final boolean isGPSOPen(final Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); // if (gps ) { // return true; // }// w ww . j a v a2 s . co m if (gps || network) { return true; } return false; }
From source file:Main.java
public static boolean isLocationEnabled(Context context) { try {/*from www. jav a 2 s . c om*/ LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:Main.java
/** * Check Network provider is enabled for location update * * @param context/* ww w. j a va 2s. 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
public static boolean isOpenGPS(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); boolean isGPSEnable = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNPEnable = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return isGPSEnable || isNPEnable; }
From source file:Main.java
public static void beginListening(Context ctx, LocationListener ll) { LocationManager lm = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); if (lm.getProvider(LocationManager.GPS_PROVIDER) != null) { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); } else if (lm.getProvider(LocationManager.NETWORK_PROVIDER) != null) { lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll); } else {/* www . j av a2s . co m*/ lm.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, ll); } }
From source file:Main.java
/** * Check GPS provider/*from w w w .j a v a 2 s .co m*/ * * @param context * @return true if enable or false if not */ public static boolean isGPSProviderEnabled(Context context) { LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); boolean value = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!value) { value = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } return value; }
From source file:Main.java
public static String getCountry(Context context) { @SuppressWarnings("static-access") LocationManager lm = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); Location l = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Geocoder gc = new Geocoder(context); try {/*from w w w. ja va2 s .c o m*/ List<Address> address = gc.getFromLocation(l.getLatitude(), l.getLongitude(), 1); if (address != null && address.isEmpty() == false) return address.get(0).getCountryName(); } catch (IOException e) { return ""; } return ""; }
From source file:Main.java
public static String getLocality(Context context) { @SuppressWarnings("static-access") LocationManager lm = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); if (lm == null) return ""; Location l = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (l == null) return ""; Geocoder gc = new Geocoder(context); try {/*from w ww . jav a 2 s .c o m*/ List<Address> address = gc.getFromLocation(l.getLatitude(), l.getLongitude(), 1); if (address != null && address.isEmpty() == false) return address.get(0).getLocality(); } catch (Exception e) { return ""; } return ""; }
From source file:Main.java
public static Location getLocation(Context context) { try {//from w w w. jav a 2 s . com 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
/** * Checks if the current device has a NETWORK module (hardware) * @return true if the current device has NETWORK *//*from w w w .ja va 2 s .c o m*/ public static boolean hasNetworkModule(final Context context) { final LocationManager locationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); for (final String provider : locationManager.getAllProviders()) { if (provider.equals(LocationManager.NETWORK_PROVIDER)) { return true; } } return false; }