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.nextgis.maplibui.service.TrackerService.java
@Override public void onCreate() { super.onCreate(); mHasGPSFix = false;// ww w . j a va 2s .c om mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); IGISApplication application = (IGISApplication) getApplication(); String authority = application.getAuthority(); mContentUriTracks = Uri.parse("content://" + authority + "/" + TrackLayer.TABLE_TRACKS); mContentUriTrackPoints = Uri.parse("content://" + authority + "/" + TrackLayer.TABLE_TRACKPOINTS); mPoint = new GeoPoint(); mValues = new ContentValues(); SharedPreferences sharedPreferences = getSharedPreferences(getPackageName() + "_preferences", Constants.MODE_MULTI_PROCESS); mSharedPreferencesTemp = getSharedPreferences(TEMP_PREFERENCES, MODE_PRIVATE); String minTimeStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_TRACKS_MIN_TIME, "2"); String minDistanceStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_TRACKS_MIN_DISTANCE, "10"); long minTime = Long.parseLong(minTimeStr) * 1000; float minDistance = Float.parseFloat(minDistanceStr); mTicker = getString(R.string.tracks_running); mSmallIcon = R.drawable.ic_action_maps_directions_walk; Intent intentSplit = new Intent(this, TrackerService.class); intentSplit.setAction(ACTION_SPLIT); mSplitService = PendingIntent.getService(this, 0, intentSplit, PendingIntent.FLAG_UPDATE_CURRENT); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!PermissionUtil.hasPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) || !PermissionUtil.hasPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)) return; mLocationManager.addGpsStatusListener(this); String provider = LocationManager.GPS_PROVIDER; if (mLocationManager.getAllProviders().contains(provider)) { mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this); if (Constants.DEBUG_MODE) Log.d(Constants.TAG, "Tracker service request location updates for " + provider); } provider = LocationManager.NETWORK_PROVIDER; if (mLocationManager.getAllProviders().contains(provider)) { mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this); if (Constants.DEBUG_MODE) Log.d(Constants.TAG, "Tracker service request location updates for " + provider); } NotificationHelper.showLocationInfo(this); }
From source file:uwp.cs.edu.parkingtracker.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); actionBarMenu = menu;//w w w. j a v a2 s . c om // if (mapTransform.isPathDrawn()) { // actionBarMenu.findItem(R.id.action_cancel).setVisible(true); // } else { // actionBarMenu.findItem(R.id.action_cancel).setVisible(false); // } locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { actionBarMenu.findItem(R.id.action_park).setVisible(true); } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { actionBarMenu.findItem(R.id.action_park).setVisible(true); } else { //location is not working actionBarMenu.findItem(R.id.action_park).setVisible(false); } return true; }
From source file:org.redbus.ui.stopmap.StopMapActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.stop_map);//from www . java2s . c om busyDialog = new BusyDialog(this); this.pointTree = StopDbHelper.Load(this); // Load in all the required BitmapDescriptors: unknownStopBitmap = BitmapDescriptorFactory.fromResource(R.drawable.stop_unknown); compassBitmaps = new HashMap<Integer, BitmapDescriptor>(); compassBitmaps.put(StopDbHelper.STOP_FACING_N, BitmapDescriptorFactory.fromResource(R.drawable.compass_n)); compassBitmaps.put(StopDbHelper.STOP_FACING_NE, BitmapDescriptorFactory.fromResource(R.drawable.compass_ne)); compassBitmaps.put(StopDbHelper.STOP_FACING_E, BitmapDescriptorFactory.fromResource(R.drawable.compass_e)); compassBitmaps.put(StopDbHelper.STOP_FACING_SE, BitmapDescriptorFactory.fromResource(R.drawable.compass_se)); compassBitmaps.put(StopDbHelper.STOP_FACING_S, BitmapDescriptorFactory.fromResource(R.drawable.compass_s)); compassBitmaps.put(StopDbHelper.STOP_FACING_SW, BitmapDescriptorFactory.fromResource(R.drawable.compass_sw)); compassBitmaps.put(StopDbHelper.STOP_FACING_W, BitmapDescriptorFactory.fromResource(R.drawable.compass_w)); compassBitmaps.put(StopDbHelper.STOP_FACING_NW, BitmapDescriptorFactory.fromResource(R.drawable.compass_nw)); compassBitmaps.put(StopDbHelper.STOP_OUTOFORDER, BitmapDescriptorFactory.fromResource(R.drawable.stop_outoforder)); compassBitmaps.put(StopDbHelper.STOP_DIVERTED, BitmapDescriptorFactory.fromResource(R.drawable.stop_diverted)); compassBitmaps = Collections.unmodifiableMap(compassBitmaps); // Get a reference to the map: SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); map = mapFragment.getMap(); if (map != null) { map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { LatLng point = marker.getPosition(); final int nearestStopNodeIdx = pointTree.findNearest((int) (point.latitude * 1E6), (int) (point.longitude * 1E6)); final int stopCode = pointTree.stopCode[nearestStopNodeIdx]; new StopMapPopup(StopMapActivity.this, stopCode); return true; } }); map.setMapType(GoogleMap.MAP_TYPE_NORMAL); map.setIndoorEnabled(false); map.setMyLocationEnabled(true); UiSettings mapSettings = map.getUiSettings(); mapSettings.setCompassEnabled(false); mapSettings.setRotateGesturesEnabled(false); mapSettings.setTiltGesturesEnabled(false); // mapController.setZoom(17); // Check to see if we've been passed data int lat = getIntent().getIntExtra("Lat", -1); int lng = getIntent().getIntExtra("Lng", -1); if (lat == -1 || lng == -1) { Log.d(TAG, "Not supplied with either lat or lng"); // if we don't have a location supplied, try and use the last known one. LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); Location gpsLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location networkLocation = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if ((gpsLocation != null) && (gpsLocation.getAccuracy() < 100)) { Log.d(TAG, "Using GPS for location. " + gpsLocation); zoomTo(new LatLng(gpsLocation.getLatitude(), gpsLocation.getLongitude())); } else if ((networkLocation != null) && (networkLocation.getAccuracy() < 100)) { Log.d(TAG, "Using network for location."); zoomTo(new LatLng(networkLocation.getLatitude(), networkLocation.getLongitude())); } else { Log.d(TAG, "Using default location from db."); StopDbHelper stopDb = StopDbHelper.Load(this); zoomTo(new LatLng(stopDb.defaultMapLocationLat / 1E6, stopDb.defaultMapLocationLon / 1E6)); } updateMyLocationStatus(true); } else { Log.d(TAG, "Using supplied lat and lng."); zoomTo(new LatLng(lat / 1E6, lng / 1E6)); updateMyLocationStatus(false); } map.setOnCameraChangeListener(this); } }
From source file:com.chalmers.schmaps.GoogleMapSearchLocation.java
/** * Method to define what the activity does on resume. * Updates the coordinates of the current position. */// w ww .j av a 2s . c o m @Override protected void onResume() { super.onResume(); try { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, UPDATEFREQUENCYINMS, UPDATEAAREA, locationListener); } catch (Exception e) { } }
From source file:br.liveo.ndrawer.ui.fragment.MainFragment.java
private void updateEvent(String event) { RequestEpcisCapture erc = new RequestEpcisCapture(); String eventDate = new SimpleDateFormat("yyyy-MM-dd").format((System.currentTimeMillis())); String eventTime = new SimpleDateFormat("HH:mm:ss").format((System.currentTimeMillis())); Location location = null;//from www. ja v a2s .co m try { if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null && mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } catch (SecurityException ex) { Log.i("Timer:", ex.getMessage()); } String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " creationDate=\"2015-01-03T11:30:47.0Z\" schemaVersion=\"1.1\" xmlns:car=\"BiPortalGs1.xsd\">\n" + " <EPCISBody>\n" + " <EventList>\n" + " <ObjectEvent>\n" + " <!-- When -->\n" + " <eventTime>" + eventDate + "T" + eventTime + ".116-10:00</eventTime>\n" + " <eventTimeZoneOffset>-10:00</eventTimeZoneOffset>\n" + " <!-- When! -->\n" + "\n" + " <!-- What -->\n" + " <epcList>\n" + " <epc>urn:epc:id:sgtin:1234567.123456.01</epc>\n" + " </epcList>\n" + " <!-- What!-->\n" + "\n" + " <!-- Add, Observe, Delete -->\n" + " <action>ADD</action>\n" + "\n" + " <!-- Why -->\n" + " <bizStep>urn:epcglobal:cbv:bizstep:" + event + "</bizStep>\n" + " <disposition>urn:epcglobal:cbv:disp:user_accessible</disposition>\n" + " <!-- Why! -->\n" + "\n" + " <!-- Where -->\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:7654321.54321.1234</id>\n" + " <extension>\n" + " <geo>" + location.getLatitude() + "," + location.getLongitude() + "</geo>\n" + " </extension>\n" + " </bizLocation>\n" + " <!-- Where! -->\n" + " </ObjectEvent>\n" + " </EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; erc.execute(xml); }
From source file:com.example.programming.proximityalerts.ProximityAlertService.java
@Override public void onLocationChanged(Location location) { float distance = getDistance(location); if (distance <= radius && !inProximity) { inProximity = true;/* w w w. ja va 2 s . co m*/ Log.i(TAG, "Entering Proximity"); Intent intent = new Intent(ProximityPendingIntentFactory.PROXIMITY_ACTION); intent.putExtra(LocationManager.KEY_PROXIMITY_ENTERING, true); sendBroadcast(intent); } else if (distance > radius && inProximity) { inProximity = false; Log.i(TAG, "Exiting Proximity"); Intent intent = new Intent(ProximityPendingIntentFactory.PROXIMITY_ACTION); intent.putExtra(LocationManager.KEY_PROXIMITY_ENTERING, true); sendBroadcast(intent); } else { float distanceFromRadius = Math.abs(distance - radius); // Calculate the distance to the edge of the user-defined radius // around the target location float locationEvaluationDistance = (distanceFromRadius - location.getAccuracy()) / 2; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 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. return; } locationManager.removeUpdates(this); float updateDistance = Math.max(1, locationEvaluationDistance); String provider; if (distanceFromRadius <= location.getAccuracy() || LocationManager.GPS_PROVIDER.equals(location.getProvider())) { provider = LocationManager.GPS_PROVIDER; } else { provider = LocationManager.NETWORK_PROVIDER; } locationManager.requestLocationUpdates(provider, 0, updateDistance, this); } }
From source file:org.hfoss.posit.android.functionplugin.reminder.SetReminder.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the transparent blank screen as a background for dialogs setContentView(R.layout.blank_screen); // Exit the Activity if the proper settings are not enabled SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean allowReminder = prefs.getBoolean("allowReminderKey", true); boolean allowGeoTag = prefs.getBoolean("geotagKey", true); // If the user allows, set the "Set Reminder" menu option if (!allowReminder || !allowGeoTag) { Toast.makeText(this, "Sorry. Geotagging and Allow Reminder settings must " + " be enabled to run the Set Reminder Activity.", Toast.LENGTH_LONG).show(); finish();// w w w . j a va 2 s.co m } mDbEntries = getIntent().getParcelableExtra("DbEntries"); dateSetPressed = false; // Get intent passed in from FindActivity Bundle bundle = getIntent().getExtras(); date = bundle.getString("Date"); // Initialize variables for Date Picker Dialog year = date.substring(0, 4); month = date.substring(5, 7); day = date.substring(8, 10); // Initialize variables for longitude and latitude findsLongitude = bundle.getDouble("FindsLongitude"); findsLatitude = bundle.getDouble("FindsLatitude"); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location netLocation = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Location gpsLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location loc = null; if (gpsLocation != null) { loc = gpsLocation; } else { loc = netLocation; } if (loc != null) { currentLongitude = loc.getLongitude(); currentLatitude = loc.getLatitude(); } showDatePickerDialog(); }
From source file:com.nextgis.maplibui.service.WalkEditService.java
private void startWalkEdit() { SharedPreferences sharedPreferences = getSharedPreferences(getPackageName() + "_preferences", Constants.MODE_MULTI_PROCESS); String minTimeStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_LOCATION_MIN_TIME, "2"); String minDistanceStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_LOCATION_MIN_DISTANCE, "10"); long minTime = Long.parseLong(minTimeStr) * 1000; float minDistance = Float.parseFloat(minDistanceStr); if (!PermissionUtil.hasPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) || !PermissionUtil.hasPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)) return;/*from w ww . j a v a 2 s . co m*/ mLocationManager.addGpsStatusListener(this); String provider = LocationManager.GPS_PROVIDER; if (mLocationManager.getAllProviders().contains(provider)) { mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this); } provider = LocationManager.NETWORK_PROVIDER; if (mLocationManager.getAllProviders().contains(provider)) { mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this); } NotificationHelper.showLocationInfo(this); initTargetIntent(mTargetActivity); addNotification(); }
From source file:be.brunoparmentier.openbikesharing.app.activities.MapActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_my_location: try {/*from ww w . j a v a2 s.c om*/ LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); GeoPoint userLocation = new GeoPoint( locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)); mapController.animateTo(userLocation); return true; } catch (NullPointerException ex) { Toast.makeText(this, getString(R.string.location_not_found), Toast.LENGTH_LONG).show(); Log.e(TAG, "Location not found"); return true; } case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; default: return super.onOptionsItemSelected(item); } }