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:com.geotrackin.gpslogger.GpsLoggingService.java
/** * This method is called periodically to determine whether the cell tower / * gps providers have been enabled, and sets class level variables to those * values.//from ww w .jav a 2s .c o m */ private void CheckTowerAndGpsStatus() { Session.setTowerEnabled(towerLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)); Session.setGpsEnabled(gpsLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)); }
From source file:com.vonglasow.michael.satstat.MapSectionFragment.java
@Override public void onStart() { super.onStart(); LayerManager layerManager = mapMap.getLayerManager(); Layers layers = layerManager.getLayers(); layers.clear();//ww w.ja va2s . c om float lat = mainActivity.mSharedPreferences.getFloat(SettingsActivity.KEY_PREF_MAP_LAT, 360.0f); float lon = mainActivity.mSharedPreferences.getFloat(SettingsActivity.KEY_PREF_MAP_LON, 360.0f); if ((lat < 360.0f) && (lon < 360.0f)) { mapMap.getModel().mapViewPosition.setCenter(new LatLong(lat, lon)); } int zoom = mainActivity.mSharedPreferences.getInt(SettingsActivity.KEY_PREF_MAP_ZOOM, 16); mapMap.getModel().mapViewPosition.setZoomLevel((byte) zoom); /* TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapMap.getModel().mapViewPosition, false, AndroidGraphicFactory.INSTANCE); //FIXME: have user select map file tileRendererLayer.setMapFile(new File(Environment.getExternalStorageDirectory(), "org.openbmap/maps/germany.map")); tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER); //tileRendererLayer.setTextScale(1.5f); layers.add(tileRendererLayer); */ mapDownloadLayer = new TileDownloadLayer(mapTileCache, mapMap.getModel().mapViewPosition, onlineTileSource, AndroidGraphicFactory.INSTANCE); layers.add(mapDownloadLayer); //parse list of location providers onLocationProvidersChanged(mainActivity.mSharedPreferences.getStringSet(SettingsActivity.KEY_PREF_LOC_PROV, new HashSet<String>(Arrays .asList(new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER })))); }
From source file:org.ozonecity.gpslogger2.GpsLoggingService.java
/** * Starts the location manager. There are two location managers - GPS and * Cell Tower. This code determines which manager to request updates from * based on user preference and whichever is enabled. If GPS is enabled on * the phone, that is used. But if the user has also specified that they * prefer cell towers, then cell towers are used. If neither is enabled, * then nothing is requested.//ww w .ja v a 2 s . c o m */ private void StartGpsManager() { GetPreferences(); //If the user has been still for more than the minimum seconds if (userHasBeenStillForTooLong()) { tracer.info("No movement in the past interval, resetting alarm"); SetAlarmForNextPoint(); return; } if (gpsLocationListener == null) { gpsLocationListener = new GeneralLocationListener(this, "GPS"); } if (towerLocationListener == null) { towerLocationListener = new GeneralLocationListener(this, "CELL"); } gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); CheckTowerAndGpsStatus(); if (Session.isGpsEnabled() && AppSettings.getChosenListeners().contains("gps")) { tracer.info("Requesting GPS location updates"); // gps satellite based gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocationListener); gpsLocationManager.addGpsStatusListener(gpsLocationListener); gpsLocationManager.addNmeaListener(gpsLocationListener); Session.setUsingGps(true); startAbsoluteTimer(); } if (Session.isTowerEnabled() && (AppSettings.getChosenListeners().contains("network") || !Session.isGpsEnabled())) { tracer.info("Requesting tower location updates"); Session.setUsingGps(false); // Cell tower and wifi based towerLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, towerLocationListener); startAbsoluteTimer(); } if (!Session.isTowerEnabled() && !Session.isGpsEnabled()) { tracer.error("No provider available!"); Session.setUsingGps(false); SetStatus(R.string.gpsprovider_unavailable); SetFatalMessage(R.string.gpsprovider_unavailable); StopLogging(); SetLocationServiceUnavailable(); return; } EventBus.getDefault().post(new ServiceEvents.WaitingForLocation(true)); Session.setWaitingForLocation(true); SetStatus(R.string.started); }
From source file:com.mendhak.gpslogger.GpsLoggingService.java
/** * Starts the location manager. There are two location managers - GPS and * Cell Tower. This code determines which manager to request updates from * based on user preference and whichever is enabled. If GPS is enabled on * the phone, that is used. But if the user has also specified that they * prefer cell towers, then cell towers are used. If neither is enabled, * then nothing is requested.// w w w . j a v a 2 s . co m */ @SuppressWarnings("ResourceType") private void startGpsManager() { //If the user has been still for more than the minimum seconds if (userHasBeenStillForTooLong()) { LOG.info("No movement detected in the past interval, will not log"); setAlarmForNextPoint(); return; } if (gpsLocationListener == null) { gpsLocationListener = new GeneralLocationListener(this, "GPS"); } if (towerLocationListener == null) { towerLocationListener = new GeneralLocationListener(this, "CELL"); } gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); checkTowerAndGpsStatus(); if (Session.isGpsEnabled() && preferenceHelper.getChosenListeners().contains(LocationManager.GPS_PROVIDER)) { LOG.info("Requesting GPS location updates"); // gps satellite based gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocationListener); gpsLocationManager.addGpsStatusListener(gpsLocationListener); gpsLocationManager.addNmeaListener(gpsLocationListener); Session.setUsingGps(true); startAbsoluteTimer(); } if (Session.isTowerEnabled() && (preferenceHelper.getChosenListeners().contains(LocationManager.NETWORK_PROVIDER) || !Session.isGpsEnabled())) { LOG.info("Requesting cell and wifi location updates"); Session.setUsingGps(false); // Cell tower and wifi based towerLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, towerLocationListener); startAbsoluteTimer(); } if (!Session.isTowerEnabled() && !Session.isGpsEnabled()) { LOG.error("No provider available!"); Session.setUsingGps(false); LOG.error(getString(R.string.gpsprovider_unavailable)); stopLogging(); setLocationServiceUnavailable(); return; } EventBus.getDefault().post(new ServiceEvents.WaitingForLocation(true)); Session.setWaitingForLocation(true); }
From source file:eu.geopaparazzi.library.gps.GpsService.java
/** * Checks if the GPS is switched on./*from w w w . j a v a 2 s .c om*/ * <p/> * <p>Does not say if the GPS is supplying valid data.</p> * * @return <code>true</code> if the GPS is switched on. */ private boolean isGpsOn() { if (locationManager == null) { return false; } boolean gpsIsEnabled; if (useNetworkPositions) { gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } else { gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } logABS("Gps is enabled: " + gpsIsEnabled); return gpsIsEnabled; }
From source file:com.crearo.gpslogger.GpsLoggingService.java
/** * Starts the location manager. There are two location managers - GPS and * Cell Tower. This code determines which manager to request updates from * based on user preference and whichever is enabled. If GPS is enabled on * the phone, that is used. But if the user has also specified that they * prefer cell towers, then cell towers are used. If neither is enabled, * then nothing is requested.//w w w . j a v a 2s . co m */ private void startGpsManager() { //If the user has been still for more than the minimum seconds if (userHasBeenStillForTooLong()) { LOG.info("No movement detected in the past interval, will not log"); setAlarmForNextPoint(); return; } if (gpsLocationListener == null) { gpsLocationListener = new GeneralLocationListener(this, "GPS"); } if (towerLocationListener == null) { towerLocationListener = new GeneralLocationListener(this, "CELL"); } gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); checkTowerAndGpsStatus(); if (Session.isGpsEnabled() && preferenceHelper.getChosenListeners().contains(LocationManager.GPS_PROVIDER)) { LOG.info("Requesting GPS location updates"); // gps satellite based gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocationListener); gpsLocationManager.addGpsStatusListener(gpsLocationListener); gpsLocationManager.addNmeaListener(gpsLocationListener); Session.setUsingGps(true); startAbsoluteTimer(); } if (Session.isTowerEnabled() && (preferenceHelper.getChosenListeners().contains(LocationManager.NETWORK_PROVIDER) || !Session.isGpsEnabled())) { LOG.info("Requesting cell and wifi location updates"); Session.setUsingGps(false); // Cell tower and wifi based towerLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, towerLocationListener); startAbsoluteTimer(); } if (!Session.isTowerEnabled() && !Session.isGpsEnabled()) { LOG.error("No provider available!"); Session.setUsingGps(false); LOG.error(getString(R.string.gpsprovider_unavailable)); stopLogging(); setLocationServiceUnavailable(); return; } EventBus.getDefault().post(new ServiceEvents.WaitingForLocation(true)); Session.setWaitingForLocation(true); }
From source file:com.klaasnotfound.locationassistant.LocationAssistant.java
private void checkProviders() { // Do it the old fashioned way LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (gps || network) return;/*from ww w . j ava2 s .c o m*/ if (listener != null) listener.onFallBackToSystemSettings(onGoToLocationSettingsFromView, onGoToLocationSettingsFromDialog); else if (!quiet) Log.e(getClass().getSimpleName(), "Location providers need to be enabled, but no listener is " + "registered! Specify a valid listener when constructing " + getClass().getSimpleName() + " or register it explicitly with register()."); }
From source file:com.landenlabs.all_devtool.GpsFragment.java
private void showProviders() { GpsInfo gpsInfo = m_list.get(s_providersRow); ItemList itemList = gpsInfo.getList(); itemList.clear();//from w w w . j a v a 2 s . c o m List<String> gpsProviders = m_locMgr.getAllProviders(); int idx = 1; for (String providerName : gpsProviders) { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { try { LocationProvider provider = m_locMgr.getProvider(providerName); if (null != provider) { int color = getProviderColor(providerName); String msg = String.format("%-10s %3s Accuracy:%d Pwr:%d", providerName, (m_locMgr.isProviderEnabled(providerName) ? "On" : "Off"), provider.getAccuracy(), provider.getPowerRequirement()); itemList.add(new GpsItem(s_noTime, msg, color)); } } catch (SecurityException ex) { m_log.e(ex.getLocalizedMessage()); m_gpsTv.setEnabled(false); addMsgToDetailRow(s_colorMsg, "GPS not available"); addMsgToDetailRow(s_colorMsg, ex.getLocalizedMessage()); } } } listChanged(); if (m_locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER)) m_statusIcon.setImageResource(R.drawable.gps_satellite); else if (m_locMgr.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) m_statusIcon.setImageResource(R.drawable.gps_tower); else if (m_locMgr.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) m_statusIcon.setImageResource(R.drawable.gps_passive); else m_statusIcon.setImageResource(R.drawable.gps_off); }
From source file:com.example.angel.parkpanda.MainActivity.java
public Location getLocation() { Location location = null;//from w w w . j av a2s . co m LocationManager locationManager; boolean isGPSEnabled = false; boolean isNetworkEnabled = false; final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; double longitude, latitude; long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; try { locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); // getting network status isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled && !isNetworkEnabled) { // no network provider is enabled } else { if (isNetworkEnabled) { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return null; } locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); } } } // if GPS Enabled get lat/long using GPS Services if (isGPSEnabled) { if (location == null) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); } } } } } } catch (Exception e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); } return location; }
From source file:com.mjhram.geodata.GpsLoggingService.java
/** * Starts the location manager. There are two location managers - GPS and * Cell Tower. This code determines which manager to request updates from * based on user preference and whichever is enabled. If GPS is enabled on * the phone, that is used. But if the user has also specified that they * prefer cell towers, then cell towers are used. If neither is enabled, * then nothing is requested.//w w w . j av a2 s . c o m */ private void StartGpsManager() { //If the user has been still for more than the minimum seconds if (userHasBeenStillForTooLong()) { tracer.info("No movement detected in the past interval, will not log"); SetAlarmForNextPoint(); return; } if (gpsLocationListener == null) { gpsLocationListener = new GeneralLocationListener(this, "GPS"); } if (towerLocationListener == null) { towerLocationListener = new GeneralLocationListener(this, "CELL"); } gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); CheckTowerAndGpsStatus(); if (Session.isGpsEnabled() && AppSettings.getChosenListeners().contains("gps")) { tracer.info("Requesting GPS location updates"); // gps satellite based gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocationListener); gpsLocationManager.addGpsStatusListener(gpsLocationListener); //gpsLocationManager.addNmeaListener(gpsLocationListener); Session.setUsingGps(true); startAbsoluteTimer(); } if (Session.isTowerEnabled() && (AppSettings.getChosenListeners().contains("network") || !Session.isGpsEnabled())) { tracer.info("Requesting cell and wifi location updates"); Session.setUsingGps(false); // Cell tower and wifi based towerLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, towerLocationListener); startAbsoluteTimer(); } if (!Session.isTowerEnabled() && !Session.isGpsEnabled()) { tracer.error("No provider available!"); Session.setUsingGps(false); tracer.error(getString(R.string.gpsprovider_unavailable)); //StopLogging(); SetLocationServiceUnavailable(); return; } EventBus.getDefault().post(new ServiceEvents.WaitingForLocation(true)); Session.setWaitingForLocation(true); }