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:de.uvwxy.whereami.ActivityMain.java
private void alertIfProviderIsNotEnabled() { boolean provEnabledGPS = LocationReader.isEnabled(this, LocationManager.GPS_PROVIDER); boolean provEnabledWiFi = LocationReader.isEnabled(this, LocationManager.NETWORK_PROVIDER); SharedPreferences pref = IntentTools.getSettings(this, SETTINGS); boolean setEnabledGPS = pref.getBoolean(SETTINGS_USE_GPS, SETTINGS_USE_GPS_DEF); boolean setEnabledWiFi = pref.getBoolean(SETTINGS_USE_WIFI, SETTINGS_USE_WIFI_DEF); pref = null;//from ww w . j a v a 2 s. c o m boolean showAlert = true; String locationProviderStateMessage = getString(R.string.waiting_for_fix); if ((!provEnabledGPS && setEnabledGPS) && (!provEnabledWiFi && setEnabledWiFi)) { locationProviderStateMessage = getString(R.string.app_load_warn_no_gps_no_wifi); } else if (!provEnabledGPS && setEnabledGPS) { locationProviderStateMessage = getString(R.string.app_load_warn_no_gps); } else if (!provEnabledWiFi && setEnabledWiFi) { locationProviderStateMessage = getString(R.string.app_load_warn_no_wifi); } else { showAlert = false; } if (showAlert) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setNegativeButton(R.string.ok, null); alertDialog.setMessage(locationProviderStateMessage); alertDialog.setTitle(R.string.enable_provider); alertDialog.show(); } }
From source file:net.fabiszewski.ulogger.LoggerService.java
/** * Reread preferences//from w w w .ja v a2s.co m */ private void updatePreferences() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); minTimeMillis = Long.parseLong(prefs.getString("prefMinTime", getString(R.string.pref_mintime_default))) * 1000; minDistance = Float .parseFloat(prefs.getString("prefMinDistance", getString(R.string.pref_mindistance_default))); maxAccuracy = Integer .parseInt(prefs.getString("prefMinAccuracy", getString(R.string.pref_minaccuracy_default))); useGps = prefs.getBoolean("prefUseGps", providerExists(LocationManager.GPS_PROVIDER)); useNet = prefs.getBoolean("prefUseNet", providerExists(LocationManager.NETWORK_PROVIDER)); liveSync = prefs.getBoolean("prefLiveSync", false); }
From source file:net.evecom.androidecssp.gps.ResourceItemizedOverlayActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); initData();//w w w .j a v a2s. c om /** 2.2 ***/ setContentView(R.layout.itemized_resource); /** 2.2 ***/ mMapView = (MapView) findViewById(R.id.itemized_mapview); mMapView.setBuiltInZoomControls(true); // Overlay // mMapView.setDrawOverlayWhenZooming(true); mController = mMapView.getController(); mCon = this; // List<Overlay> list = mMapView.getOverlays(); centerGpsPoint = new GeoPoint((int) (26.031846613632812 * 1E6), (int) (119.4909095748828 * 1E6)); mController.setCenter(centerGpsPoint); sp = instance.getSharedPreferences("GPS", instance.MODE_PRIVATE); myLocation = new MyGpsLocationOverlay(this, mMapView, new MyGpsLocationOverlay.MyGpsLocationOverlayinterface() { @Override public void onLocationChanged(Location location, GeoPoint geoPoint) { Editor editor = sp.edit(); editor.putString("latitude", "" + location.getLatitude()); editor.putString("longitude", "" + location.getLongitude()); editor.commit(); String strLog = String.format(":\r\n" + ":%f\r\n" + ":%f", location.getLongitude(), location.getLatitude()); Toast.makeText(instance, strLog, Toast.LENGTH_SHORT).show(); if (!ismanuallocation) { centerGpsPoint = geoPoint; } } }); myLocation.enableCompass(); myLocation.enableMyLocation(); list.add(myLocation); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, myLocation); } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, myLocation); } list.add(new ManualLocationOverlay(this, new ManualLocationOverlay.ManualMapOnCilck() { @Override public void mapclick(GeoPoint point, MapView mapView) { ismanuallocation = true; centerGpsPoint = point; } }));// // initAroundDialog(); initOtherView(); }
From source file:org.klnusbaum.udj.EventListFragment.java
public void onStart() { super.onStart(); lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(false); if (providers.contains(LocationManager.GPS_PROVIDER)) { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 50, this); if (lastKnown == null) { lastKnown = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); }/*from ww w. ja v a2 s. c o m*/ } if (providers.contains(LocationManager.NETWORK_PROVIDER)) { lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 50, this); if (lastKnown == null) { lastKnown = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } if (lastSearch == null) { lastSearch = new LocationEventSearch(lastKnown); } }
From source file:com.ibm.mf.geofence.demo.MapsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { log.debug("***************************************************************************************"); super.onCreate(savedInstanceState); setContentView(R.layout.maps_activity); mapCrossHair = (ImageView) findViewById(R.id.map_cross_hair); log.debug("in onCreate() tracking is " + (trackingEnabled ? "enabled" : "disabled")); addFenceButton = (Button) findViewById(R.id.addFenceButton); addFenceButton.setOnClickListener(new View.OnClickListener() { @Override// w ww . ja v a 2 s . c o m public void onClick(View v) { switchMode(); } }); if (savedInstanceState != null) { double[] loc = savedInstanceState.getDoubleArray("currentLocation"); if (loc != null) { currentLocation = new Location(LocationManager.NETWORK_PROVIDER); currentLocation.setLatitude(loc[0]); currentLocation.setLongitude(loc[1]); currentLocation.setTime(System.currentTimeMillis()); } currentZoom = savedInstanceState.getFloat("zoom", -1f); log.debug(String.format("restored currentLocation=%s; currentZoom=%f", currentLocation, currentZoom)); } if (currentLocation == null) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); currentLocation = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } log.debug("onCreate() : init of geofencing service"); /* if (!dbDeleted) { dbDeleted = true; DemoUtils.deleteGeofenceDB(this); } */ initManager(); /* // testing the loading from a zip resource manager.loadGeofencesFromResource("com/ibm/pisdk/geofencing/geofence_2016-03-18_14_38_04.zip"); */ customHttpService = new CustomHttpService(manager, this, SERVER_URL, USER, PWD); try { startSimulation(geofenceHolder.getFences()); } catch (Exception e) { log.error("error in startSimulation()", e); } }
From source file:com.nextgis.maplibui.fragment.CompassFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (null == getParentFragment()) { setRetainInstance(true);//from ww w .j a v a 2 s .co m } // reference to vibrator service mDeclination = 0; mVibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (!PermissionUtil.hasPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) || !PermissionUtil.hasPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)) return; if (mCurrentLocation == null) { LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (mCurrentLocation == null) { mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } if (mCurrentLocation != null) mDeclination = getDeclination(mCurrentLocation, System.currentTimeMillis()); }
From source file:com.example.android.location.LocationActivity.java
private void setup() { Location gpsLocation = null;/*w w w . ja va 2s . c o m*/ Location networkLocation = null; mLocationManager.removeUpdates(listener); mLatLng.setText(R.string.unknown); mAddress.setText(R.string.unknown); // Get fine location updates only. if (mUseFine) { mFineProviderButton.setBackgroundResource(R.drawable.button_active); mBothProviderButton.setBackgroundResource(R.drawable.button_inactive); // Request updates from just the fine (gps) provider. gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps); // Update the UI immediately if a location is obtained. if (gpsLocation != null) updateUILocation(gpsLocation); } else if (mUseBoth) { // Get coarse and fine location updates. mFineProviderButton.setBackgroundResource(R.drawable.button_inactive); mBothProviderButton.setBackgroundResource(R.drawable.button_active); // Request updates from both fine (gps) and coarse (network) providers. gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps); networkLocation = requestUpdatesFromProvider(LocationManager.NETWORK_PROVIDER, R.string.not_support_network); // If both providers return last known locations, compare the two and use the better // one to update the UI. If only one provider returns a location, use it. if (gpsLocation != null && networkLocation != null) { updateUILocation(getBetterLocation(gpsLocation, networkLocation)); } else if (gpsLocation != null) { updateUILocation(gpsLocation); } else if (networkLocation != null) { updateUILocation(networkLocation); } } }
From source file:com.facebook.react.modules.location.LocationModule.java
@Nullable private String getValidProvider(LocationManager locationManager, boolean highAccuracy) { String provider = highAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER; if (!locationManager.isProviderEnabled(provider)) { provider = provider.equals(LocationManager.GPS_PROVIDER) ? LocationManager.NETWORK_PROVIDER : LocationManager.GPS_PROVIDER; if (!locationManager.isProviderEnabled(provider)) { return null; }//from w w w . j av a 2 s . c o m } // If it's an enabled provider, but we don't have permissions, ignore it int finePermission = ContextCompat.checkSelfPermission(getReactApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION); if (provider.equals(LocationManager.GPS_PROVIDER) && finePermission != PackageManager.PERMISSION_GRANTED) { return null; } return provider; }
From source file:com.sorin.cloudcog.xivelypull.LocationActivity.java
private void setup() { Location gpsLocation = null;// w w w. j a va 2 s .c o m Location networkLocation = null; mLocationManager.removeUpdates(listener); mLatLng.setText(R.string.unknown); mAddress.setText(R.string.unknown); // Get fine location updates only. if (mUseFine) { mFineProviderButton.setBackgroundResource(R.drawable.button_active); mBothProviderButton.setBackgroundResource(R.drawable.button_inactive); // Request updates from just the fine (gps) provider. gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps); // Update the UI immediately if a location is obtained. if (gpsLocation != null) updateUILocation(gpsLocation); } else if (mUseBoth) { // Get coarse and fine location updates. mFineProviderButton.setBackgroundResource(R.drawable.button_inactive); mBothProviderButton.setBackgroundResource(R.drawable.button_active); // Request updates from both fine (gps) and coarse (network) // providers. gpsLocation = requestUpdatesFromProvider(LocationManager.GPS_PROVIDER, R.string.not_support_gps); networkLocation = requestUpdatesFromProvider(LocationManager.NETWORK_PROVIDER, R.string.not_support_network); // If both providers return last known locations, compare the two // and use the better // one to update the UI. If only one provider returns a location, // use it. if (gpsLocation != null && networkLocation != null) { updateUILocation(getBetterLocation(gpsLocation, networkLocation)); } else if (gpsLocation != null) { updateUILocation(gpsLocation); } else if (networkLocation != null) { updateUILocation(networkLocation); } } }
From source file:csic.ceab.movelab.beepath.FixGet.java
public void onStart(Intent intent, int startId) { if (fixInProgress == false) { fixInProgress = true;/*from w w w. j a v a 2s. c o m*/ stopFilter = new IntentFilter(Util.createInternalMessage(Util.MESSAGE_STOP_FIXGET, context)); stopReceiver = new StopReceiver(); registerReceiver(stopReceiver, stopFilter); announceFixStarted(); if (PropertyHolder.useSensorACCELEROMETER()) startService(new Intent(FixGet.this, SensorGetAccelerometer.class)); if (PropertyHolder.useSensorMAGNETIC_FIELD()) startService(new Intent(FixGet.this, SensorGetMagneticField.class)); if (PropertyHolder.useSensorORIENTATION()) startService(new Intent(FixGet.this, SensorGetOrientation.class)); if (PropertyHolder.useSensorGRAVITY()) startService(new Intent(FixGet.this, SensorGetGravity.class)); if (PropertyHolder.useSensorLINEAR_ACCELERATION()) startService(new Intent(FixGet.this, SensorGetLinear_Acceleration.class)); if (PropertyHolder.useSensorGYROSCOPE()) startService(new Intent(FixGet.this, SensorGetGyroscope.class)); // stopListening = null; bestLocation = null; if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { if (Util.flushGPSFlag == true) { clearGPS(); injectNewXTRA(); Util.flushGPSFlag = false; } locationListener1 = new mLocationListener(); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener1); // mGpsStatusListener= new GpsStatusListener(); // locationManager.addGpsStatusListener(mGpsStatusListener); } if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationListener2 = new mLocationListener(); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener2); } } }