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.androzic.MapActivity.java
@Override protected void onResume() { super.onResume(); Log.e(TAG, "onResume()"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); Resources resources = getResources(); // update some preferences int speedIdx = Integer.parseInt(settings.getString(getString(R.string.pref_unitspeed), "0")); speedFactor = Double.parseDouble(resources.getStringArray(R.array.speed_factors)[speedIdx]); speedAbbr = resources.getStringArray(R.array.speed_abbrs)[speedIdx]; speedUnit.setText(speedAbbr);/* w w w.ja v a 2 s. c o m*/ int distanceIdx = Integer.parseInt(settings.getString(getString(R.string.pref_unitdistance), "0")); StringFormatter.distanceFactor = Double .parseDouble(resources.getStringArray(R.array.distance_factors)[distanceIdx]); StringFormatter.distanceAbbr = resources.getStringArray(R.array.distance_abbrs)[distanceIdx]; StringFormatter.distanceShortFactor = Double .parseDouble(resources.getStringArray(R.array.distance_factors_short)[distanceIdx]); StringFormatter.distanceShortAbbr = resources.getStringArray(R.array.distance_abbrs_short)[distanceIdx]; int elevationIdx = Integer.parseInt(settings.getString(getString(R.string.pref_unitelevation), "0")); elevationFactor = Double.parseDouble(resources.getStringArray(R.array.elevation_factors)[elevationIdx]); elevationAbbr = resources.getStringArray(R.array.elevation_abbrs)[elevationIdx]; elevationUnit.setText(elevationAbbr); application.angleType = Integer.parseInt(settings.getString(getString(R.string.pref_unitangle), "0")); trackUnit.setText((application.angleType == 0 ? "deg" : getString(R.string.degmag))); bearingUnit.setText((application.angleType == 0 ? "deg" : getString(R.string.degmag))); application.coordinateFormat = Integer .parseInt(settings.getString(getString(R.string.pref_unitcoordinate), "0")); application.sunriseType = Integer.parseInt(settings.getString(getString(R.string.pref_unitsunrise), "0")); renderInterval = settings.getInt(getString(R.string.pref_maprenderinterval), resources.getInteger(R.integer.def_maprenderinterval)) * 100; followOnLocation = settings.getBoolean(getString(R.string.pref_mapfollowonloc), resources.getBoolean(R.bool.def_mapfollowonloc)); magInterval = resources.getInteger(R.integer.def_maginterval) * 1000; showDistance = Integer.parseInt(settings.getString(getString(R.string.pref_showdistance_int), getString(R.string.def_showdistance))); showAccuracy = settings.getBoolean(getString(R.string.pref_showaccuracy), true); autoDim = settings.getBoolean(getString(R.string.pref_mapdim), resources.getBoolean(R.bool.def_mapdim)); dimInterval = settings.getInt(getString(R.string.pref_mapdiminterval), resources.getInteger(R.integer.def_mapdiminterval)) * 1000; dimValue = settings.getInt(getString(R.string.pref_mapdimvalue), resources.getInteger(R.integer.def_mapdimvalue)); map.setHideOnDrag(settings.getBoolean(getString(R.string.pref_maphideondrag), resources.getBoolean(R.bool.def_maphideondrag))); map.setStrictUnfollow(!settings.getBoolean(getString(R.string.pref_unfollowontap), resources.getBoolean(R.bool.def_unfollowontap))); map.setLookAhead( settings.getInt(getString(R.string.pref_lookahead), resources.getInteger(R.integer.def_lookahead))); map.setBestMapEnabled( settings.getBoolean(getString(R.string.pref_mapbest), resources.getBoolean(R.bool.def_mapbest))); map.setBestMapInterval(settings.getInt(getString(R.string.pref_mapbestinterval), resources.getInteger(R.integer.def_mapbestinterval)) * 1000); map.setCursorVector( Integer.parseInt(settings.getString(getString(R.string.pref_cursorvector), getString(R.string.def_cursorvector))), settings.getInt(getString(R.string.pref_cursorvectormlpr), resources.getInteger(R.integer.def_cursorvectormlpr))); map.setProximity(Integer.parseInt(settings.getString(getString(R.string.pref_navigation_proximity), getString(R.string.def_navigation_proximity)))); // prepare views customizeLayout(settings); findViewById(R.id.editroute).setVisibility(application.editingRoute != null ? View.VISIBLE : View.GONE); if (application.editingTrack != null) { startEditTrack(application.editingTrack); } updateGPSStatus(); updateNavigationStatus(); // prepare overlays updateOverlays(settings, false); if (settings.getBoolean(getString(R.string.ui_drawer_open), false)) { Panel panel = (Panel) findViewById(R.id.panel); panel.setOpen(true, false); } onSharedPreferenceChanged(settings, getString(R.string.pref_wakelock)); map.setKeepScreenOn(keepScreenOn); // TODO move into application if (lastKnownLocation != null) { if (lastKnownLocation.getProvider().equals(LocationManager.GPS_PROVIDER)) { updateMovingInfo(lastKnownLocation, true); updateNavigationInfo(); dimScreen(lastKnownLocation); } else if (lastKnownLocation.getProvider().equals(LocationManager.NETWORK_PROVIDER)) { dimScreen(lastKnownLocation); } } bindService(new Intent(this, LocationService.class), locationConnection, BIND_AUTO_CREATE); bindService(new Intent(this, NavigationService.class), navigationConnection, BIND_AUTO_CREATE); registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.BROADCAST_NAVIGATION_STATUS)); registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.BROADCAST_NAVIGATION_STATE)); registerReceiver(broadcastReceiver, new IntentFilter(LocationService.BROADCAST_LOCATING_STATUS)); registerReceiver(broadcastReceiver, new IntentFilter(LocationService.BROADCAST_TRACKING_STATUS)); registerReceiver(broadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); registerReceiver(broadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); if (application.hasEnsureVisible()) { setFollowing(false); double[] loc = application.getEnsureVisible(); application.setMapCenter(loc[0], loc[1], true, false); application.clearEnsureVisible(); } else { application.updateLocationMaps(true, map.isBestMapEnabled()); } updateMapViewArea(); map.resume(); map.updateMapInfo(); map.update(); map.requestFocus(); }
From source file:com.vonglasow.michael.satstat.MapSectionFragment.java
/** * Updates the list of styles to use for the location providers. * /*from w w w. ja va2 s . co m*/ * This method updates the internal list of styles to use for displaying * locations on the map, assigning a style to each location provider. * Styles that are defined in {@link SharedPreferences} are preserved. If * none are defined, the GPS location provider is assigned the red style * and the network location provider is assigned the blue style. The * passive location provider is not assigned a style, as it does not send * any locations of its own. Other location providers are assigned one of * the following styles: green, orange, purple. If there are more location * providers than styles, the same style (including red and blue) can be * assigned to multiple providers. The mapping is written to * SharedPreferences so that it will be preserved even as available * location providers change. */ public void updateLocationProviderStyles() { //FIXME: move code into assignLocationProviderStyle and use that List<String> allProviders = mainActivity.locationManager.getAllProviders(); allProviders.remove(LocationManager.PASSIVE_PROVIDER); if (allProviders.contains(LocationManager.GPS_PROVIDER)) { providerStyles.put(LocationManager.GPS_PROVIDER, mainActivity.mSharedPreferences.getString( SettingsActivity.KEY_PREF_LOC_PROV_STYLE + LocationManager.GPS_PROVIDER, LOCATION_PROVIDER_RED)); mAvailableProviderStyles.remove(LOCATION_PROVIDER_RED); allProviders.remove(LocationManager.GPS_PROVIDER); } if (allProviders.contains(LocationManager.NETWORK_PROVIDER)) { providerStyles.put(LocationManager.NETWORK_PROVIDER, mainActivity.mSharedPreferences.getString( SettingsActivity.KEY_PREF_LOC_PROV_STYLE + LocationManager.NETWORK_PROVIDER, LOCATION_PROVIDER_BLUE)); mAvailableProviderStyles.remove(LOCATION_PROVIDER_BLUE); allProviders.remove(LocationManager.NETWORK_PROVIDER); } for (String prov : allProviders) { if (mAvailableProviderStyles.isEmpty()) mAvailableProviderStyles.addAll(Arrays.asList(LOCATION_PROVIDER_STYLES)); providerStyles.put(prov, mainActivity.mSharedPreferences .getString(SettingsActivity.KEY_PREF_LOC_PROV_STYLE + prov, mAvailableProviderStyles.get(0))); mAvailableProviderStyles.remove(providerStyles.get(prov)); } ; SharedPreferences.Editor spEditor = mainActivity.mSharedPreferences.edit(); for (String prov : providerStyles.keySet()) spEditor.putString(SettingsActivity.KEY_PREF_LOC_PROV_STYLE + prov, providerStyles.get(prov)); spEditor.commit(); }
From source file:com.crearo.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 a2s. c om */ private void checkTowerAndGpsStatus() { Session.setTowerEnabled(towerLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)); Session.setGpsEnabled(gpsLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)); }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
@Override protected void onResume() { super.onResume(); try {/*from w ww .ja v a2 s.c o m*/ this.mWakeLock.acquire(); // ?? ? killOnError(); // ? ? mixContext.mixView = this; // ?? dataView.doStart(); // ?? dataView.clearEvents(); // ? ? double angleX, angleY; // ? x, y /*? ? ? */ angleX = Math.toRadians(-90); m1.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f, (float) Math.sin(angleX), (float) Math.cos(angleX)); angleX = Math.toRadians(-90); angleY = Math.toRadians(-90); m2.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f, (float) Math.sin(angleX), (float) Math.cos(angleX)); m3.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f, (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY)); m4.toIdentity(); for (int i = 0; i < histR.length; i++) { histR[i] = new Matrix(); } /* */ // ? sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE); // ? ? // ?? sensors = sensorMgr.getSensorList(Sensor.TYPE_ACCELEROMETER); if (sensors.size() > 0) { sensorGrav = sensors.get(0); } // ? sensors = sensorMgr.getSensorList(Sensor.TYPE_MAGNETIC_FIELD); if (sensors.size() > 0) { sensorMag = sensors.get(0); } //// TODO: 2016-06-01 if (sensors.size() > 0) { sensors = sensorMgr_ori.getSensorList(Sensor.TYPE_ORIENTATION); orientationSensor = sensors.get(0); } // ?? ? ? ? ? sensorMgr.registerListener(this, sensorGrav, SENSOR_DELAY_GAME); sensorMgr.registerListener(this, sensorMag, SENSOR_DELAY_GAME); if (orientationSensor != null) { sensorMgr_ori.registerListener(this, orientationSensor, sensorMgr_ori.SENSOR_DELAY_GAME); } try { // ?? (Criteria) // http://developer.android.com/reference/android/location/Criteria.html Criteria c = new Criteria(); // ? c.setAccuracy(Criteria.ACCURACY_FINE); //c.setBearingRequired(true); // ? locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // ?? ? ? ? . 2 , 3 locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 4, this); // ?? ? , String bestP = locationMgr.getBestProvider(c, true); isGpsEnabled = locationMgr.isProviderEnabled(bestP); // gps, ? ? ? Location hardFix = new Location("reverseGeocoded"); try { // ? gps, ?? Location gps = locationMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location network = locationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // ? ? // gps > ? > if (gps != null) mixContext.curLoc = gps; else if (network != null) mixContext.curLoc = network; else mixContext.curLoc = hardFix; } catch (Exception ex2) { // ? ex2.printStackTrace(); // mixContext.curLoc = hardFix; // } // ? ? ?? mixContext.setLocationAtLastDownload(mixContext.curLoc); // ?? . ? GeomagneticField gmf = new GeomagneticField((float) mixContext.curLoc.getLatitude(), (float) mixContext.curLoc.getLongitude(), (float) mixContext.curLoc.getAltitude(), System.currentTimeMillis()); // ?? angleY = Math.toRadians(-gmf.getDeclination()); m4.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f, (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY)); mixContext.declination = gmf.getDeclination(); } catch (Exception ex) { Log.d("mixare", "GPS Initialize Error", ex); // ? } // ? downloadThread = new Thread(mixContext.downloadManager); downloadThread.start(); } catch (Exception ex) { doError(ex); // ? try { // ??? if (sensorMgr != null) { sensorMgr.unregisterListener(this, sensorGrav); sensorMgr.unregisterListener(this, sensorMag); sensorMgr = null; } // ?? if (locationMgr != null) { locationMgr.removeUpdates(this); locationMgr = null; } // ?? ?? if (mixContext != null) { if (mixContext.downloadManager != null) mixContext.downloadManager.stop(); } } catch (Exception ignore) { } } // ?? // ?? ? ( ?? ) ? if (dataView.isFrozen() && searchNotificationTxt == null) { searchNotificationTxt = new TextView(this); searchNotificationTxt.setWidth(dWindow.getWidth()); searchNotificationTxt.setPadding(10, 2, 0, 0); searchNotificationTxt.setBackgroundColor(Color.DKGRAY); searchNotificationTxt.setTextColor(Color.WHITE); searchNotificationTxt.setOnTouchListener(this); addContentView(searchNotificationTxt, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } else if (!dataView.isFrozen() && searchNotificationTxt != null) { searchNotificationTxt.setVisibility(View.GONE); searchNotificationTxt = null; } }
From source file:com.eeshana.icstories.activities.UploadVideoActivity.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE && resultCode == 0) { String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if (provider != null) { //Log.v(TAG, " Location providers: "+provider); //Start searching for location and update the location text when update available. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } else {/*from w ww . j a va2 s . co m*/ //Users did not switch on the GPS // showCustomToast.showToast(SharePhotoActivity.this, " "); locationDialog.show(); } } }
From source file:net.jongrakko.zipsuri.activity.PostReviseActivity.java
@Override public boolean onMyLocationButtonClick() { LocationManager mLocationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { ProgressManger.showToast(" ."); } else {/*from ww w . j a v a 2s . c om*/ ProgressManger.showToast(" ..."); } return false; }
From source file:com.tdispatch.passenger.fragment.ControlCenterFragment.java
protected void moveMapToLocation(LatLng location, Boolean disableAnimation, Boolean resetCamera) { MapFragment mapFragment = (MapFragment) mFragmentManager.findFragmentById(R.id.map_fragment); if (mapFragment != null) { GoogleMap map = mapFragment.getMap(); if (map != null) { if (location == null) { Location tmp = map.getMyLocation(); if (tmp != null) { location = new LatLng(tmp.getLatitude(), tmp.getLongitude()); }/*from w w w. j av a 2 s. c om*/ } if (location == null) { Location lastKnownLoc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (lastKnownLoc == null) { lastKnownLoc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } if (lastKnownLoc != null) { location = new LatLng(lastKnownLoc.getLatitude(), lastKnownLoc.getLongitude()); } } if (location != null) { CameraUpdate cameraUpdate; if (resetCamera) { CameraPosition cameraPosition = new CameraPosition.Builder().target(location).zoom(15f) .bearing(0f).tilt(0).build(); cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition); } else { cameraUpdate = CameraUpdateFactory.newLatLng(location); } if (disableAnimation) { map.moveCamera(cameraUpdate); } else { map.animateCamera(cameraUpdate); } } else { NoLocationDialogFragment frag = NoLocationDialogFragment.newInstance( GenericDialogFragment.DIALOG_TYPE_ERROR, getString(R.string.unable_to_get_current_location_body), getString(R.string.unable_to_get_current_location_button_show_settings)); frag.setTargetFragment(mMe, 0); frag.show(((FragmentActivity) mParentActivity).getSupportFragmentManager(), "nolocationdialog"); } } } }
From source file:com.raddapp.radika.raddappv001.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.// w w w .j av a 2 s . c o m */ private void CheckTowerAndGpsStatus() { Log.d("GPSLOGSERV 101", "CheckTowerAndGpsStatus"); Session.setTowerEnabled(towerLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)); Session.setGpsEnabled(gpsLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)); }
From source file:com.androzic.location.LocationService.java
@Override public void onLocationChanged(final Location location) { tics++;// www . j a va 2 s. c o m boolean fromGps = false; boolean sendUpdate = false; long time = SystemClock.elapsedRealtime(); // Log.i(TAG, "Location arrived: "+location.toString()); if (LocationManager.NETWORK_PROVIDER.equals(location.getProvider())) { if (useNetwork && (gpsStatus == GPS_OFF || (gpsStatus == GPS_SEARCHING && time > lastLocationMillis + gpsLocationTimeout))) { Log.d(TAG, "New location"); lastKnownLocation = location; lastLocationMillis = time; isContinous = false; sendUpdate = true; } else { return; } } else { fromGps = true; Log.d(TAG, "Fix arrived"); long prevLocationMillis = lastLocationMillis; float prevSpeed = lastKnownLocation.getSpeed(); lastKnownLocation = location; lastLocationMillis = time; sendUpdate = true; if (!Float.isNaN(nmeaGeoidHeight)) { location.setAltitude(location.getAltitude() + nmeaGeoidHeight); } if (justStarted) { justStarted = prevSpeed == 0; } else if (lastKnownLocation.getSpeed() > 0) { // filter speed outrages double a = 2 * 9.8 * (lastLocationMillis - prevLocationMillis) / 1000; if (Math.abs(lastKnownLocation.getSpeed() - prevSpeed) > a) lastKnownLocation.setSpeed(prevSpeed); } // smooth speed float smoothspeed = 0; float curspeed = lastKnownLocation.getSpeed(); for (int i = speed.length - 1; i > 1; i--) { smoothspeed += speed[i]; speed[i] = speed[i - 1]; } smoothspeed += speed[1]; if (speed[1] < speed[0] && speed[0] > curspeed) { speed[0] = (speed[1] + curspeed) / 2; } smoothspeed += speed[0]; speed[1] = speed[0]; lastKnownLocation.setSpeed(speed[1]); speed[0] = curspeed; if (speed[0] == 0 && speed[1] == 0) smoothspeed = 0; else smoothspeed = smoothspeed / speed.length; // average speed float avspeed = 0; for (int i = speedav.length - 1; i >= 0; i--) { avspeed += speedav[i]; } avspeed = avspeed / speedav.length; if (tics % pause == 0) { if (avspeed > 0) { float diff = curspeed / avspeed; if (0.95 < diff && diff < 1.05) { for (int i = speedav.length - 1; i > 0; i--) { speedav[i] = speedav[i - 1]; } speedav[0] = curspeed; } } float fluct = 0; for (int i = speedavex.length - 1; i > 0; i--) { fluct += speedavex[i] / curspeed; speedavex[i] = speedavex[i - 1]; } fluct += speedavex[0] / curspeed; speedavex[0] = curspeed; fluct = fluct / speedavex.length; if (0.95 < fluct && fluct < 1.05) { for (int i = speedav.length - 1; i >= 0; i--) { speedav[i] = speedavex[i]; } if (pause < 5) pause++; } } smoothSpeed = smoothspeed; avgSpeed = avspeed; } /* * lastKnownLocation.setSpeed(20); lastKnownLocation.setBearing(55); * lastKnownLocation.setAltitude(169); * lastKnownLocation.setLatitude(55.852527); * lastKnownLocation.setLongitude(29.451150); */ if (sendUpdate) updateLocation(); isContinous = fromGps; }
From source file:net.kidlogger.kidlogger.KLService.java
private void startGpsUpdates() { long minTime = 0; float minDist = 0; try {//from ww w . j ava 2s .c om minTime = Long.parseLong(Settings.getGpsUpdatesTime(this)); minDist = Float.parseFloat(Settings.getMinDistance(this)); } catch (NumberFormatException e) { minTime = MIN * 5L; minDist = 20.0f; app.logError(CN + "startGpsUpdates", e.toString()); } //List<String> locProviders = locMngr.getAllProviders(); locListener = new KidLocListener(); if (locMngr.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locMngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime * MIN, minDist, locListener); //Log.i(CN, "GPS location"); } else if (locMngr.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locMngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTime * MIN, minDist, locListener); //Log.i(CN, "Network location"); } else gpsOn = false; /* if(gpsOn) locMngr.removeUpdates(onLocationChange); try{ locMngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime * MIN, minDist, onLocationChange); //locMngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTime * MIN, // minDist, onLocationChange); Log.i("KLS", "Min time: " + minTime + "min dist: " + minDist); }catch(IllegalArgumentException e){ app.logError(CN + "startGpsUpdates", e.toString()); }catch(SecurityException e){ app.logError(CN + "startGpsUpdates", e.toString()); } */ }