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
private static Location getLastBestLocation(Context pContext) { LocationManager locationManager = (LocationManager) pContext.getSystemService(Context.LOCATION_SERVICE); Location locationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location locationNet = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); long GPSLocationTime = 0; if (null != locationGPS) { GPSLocationTime = locationGPS.getTime(); }//from w ww.j ava 2 s .c om long NetLocationTime = 0; if (null != locationNet) { NetLocationTime = locationNet.getTime(); } if (0 < GPSLocationTime - NetLocationTime) { Log.e(TAG, "Located by GPS"); return locationGPS; } else { Log.e(TAG, "Located by network"); return locationNet; } }
From source file:com.prey.actions.location.LocationUtil.java
public static HttpDataService dataLocation(Context ctx) { HttpDataService data = null;/*ww w .j a v a 2 s . c om*/ 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:com.digzdigital.eservicedriver.SimplePositionProvider.java
public SimplePositionProvider(Context context, PositionListener listener) { super(context, listener); if (!type.equals(LocationManager.NETWORK_PROVIDER)) { type = LocationManager.GPS_PROVIDER; }/*from w ww. j a va2 s . co m*/ }
From source file:Main.java
/** Returns true if network provider is enabled, otherwise false. */ public static final boolean isNetworkEnabled() { loadLocationManager();//from w w w .j a va 2 s.co m try { return mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception e) { // If exception occurs, then there is no network provider available. return false; } }
From source file:disono.webmons.com.utilities.sensor.GeoLocation.GPS.java
public void run(LocationListener listener) { if (ActivityCompat.checkSelfPermission(application, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(application, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.e(TAG, "GPS is not available or enabled on this device."); return;//from w w w. j a va 2s .c om } this.manager().requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener); }
From source file:uk.org.freeflight.wifefinder.WifeFinderLocationService.java
void start() { location.removeAccuracy();/*from w ww . j ava 2 s . c o m*/ if (checkPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); running = true; } if (checkPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION)) { if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); running = true; } } }
From source file:it.feio.android.omninotes.utils.GeocodeHelper.java
public static LocationManager getLocationManager(Context context, final LocationListener locationListener) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // A check is done to avoid crash when NETWORK_PROVIDER is not // available (ex. on emulator with API >= 11) if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER) && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 50, locationListener); }//from w w w .j a v a 2s . co m if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER) && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 50, locationListener); } else { locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 60000, 50, locationListener); } return locationManager; }
From source file:com.example.techniche.locationaddress.MyLocation.java
public boolean getLocation(Context context, LocationResult result) { locationResult = result;// w w w .j a v a2 s.c o m this.context = context; if (lm == null) lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // exceptions will be thrown if provider is not permitted. try { gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { } try { network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception ex) { } // don't start listeners if no provider is enabled if (!gps_enabled && !network_enabled) return false; if (gps_enabled) { if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. } else { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps); } } if (network_enabled) lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork); timer1 = new Timer(); timer1.schedule(new GetLastLocation(), 20000); return true; }
From source file:id.satusatudua.sigap.service.LocationReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (!BenihUtils.isMyServiceRunning(context, LocationService.class)) { context.startService(new Intent(context, LocationService.class)); }//from w w w .j av a 2 s.c o m LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); boolean anyLocationProv = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); anyLocationProv |= locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!anyLocationProv) { Notification notification = new NotificationCompat.Builder(context).setContentTitle("Sigap") .setContentText("Fitur lokasi tidak aktif.") .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setSmallIcon(R.mipmap.ic_launcher).setOngoing(true).setAutoCancel(true) .setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle() .bigText("Aktifkan fitur lokasi agar Sigap bisa berjalan dengan baik.")) .build(); NotificationManagerCompat.from(SigapApp.pluck().getApplicationContext()).notify(25061993, notification); } else { NotificationManagerCompat.from(SigapApp.pluck().getApplicationContext()).cancel(25061993); } }
From source file:com.daoofdev.weatherday.LocationWrapper.java
private static String getPreferredProvider() { if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) return LocationManager.GPS_PROVIDER; if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) return LocationManager.NETWORK_PROVIDER; return null;/*from w w w . ja va 2s . c o m*/ }