List of usage examples for android.location LocationManager GPS_PROVIDER
String GPS_PROVIDER
To view the source code for android.location LocationManager GPS_PROVIDER.
Click Source Link
From source file:com.example.leandromaguna.myapp.Presentation.PlacesMap.PlacesMapActivity.java
/** * Enables the My Location layer if the fine location permission has been granted. *//*from w w w . j a v a 2 s.c o m*/ private void enableMyLocation() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission to access the location is missing. PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE, Manifest.permission.ACCESS_FINE_LOCATION, true); } else if (mMap != null) { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); return; } // Access to the location has been granted to the app. mMap.setMyLocationEnabled(true); // mMap.setLocationSource(mLocationSource); // mMap.setOnMapLongClickListener(mLocationSource); // Log.d(TAG, "enableMyLocation()"); if (selectedLocation != null) { mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(selectedLocation, 15)); } } }
From source file:com.findcab.driver.activity.Signup.java
private boolean initGPS() { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // GPS????/*from w w w . jav a 2 s . com*/ if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { Toast.makeText(this, "GPS is not open,Please open it!", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0); return false; } else { Toast.makeText(this, "GPS is ready", Toast.LENGTH_SHORT); } return true; }
From source file:com.adampmarshall.speedo.LocationActivity.java
private void setup() { Location gpsLocation = null;/*from ww w. j a v a2 s .com*/ Location networkLocation = null; mLocationManager.removeUpdates(listener); mSpeed.setText(R.string.unknown); // Get fine location updates only. if (mUseFine) { // 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) { // 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: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;/* w ww .java2s . c om*/ 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.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;// w w w .java 2 s. c o 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:com.example.programming.proximityalerts.ProximityAlertService.java
@Override public void onLocationChanged(Location location) { float distance = getDistance(location); if (distance <= radius && !inProximity) { inProximity = true;/*from w w w. j a v a 2 s . c o 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:com.kentli.cycletrack.RecordingActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.recording);//from ww w. j a va2s. c om initWidget(); if (rService == null) rService = new Intent(RecordingActivity.this, RecordingService.class); startService(rService); ServiceConnection sc = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { } public void onServiceConnected(ComponentName name, IBinder service) { IRecordService rs = (IRecordService) service; recordService = rs; int state = rs.getState(); updateUIAccordingToState(rs.getState()); if (state > RecordingService.STATE_IDLE) { if (state == RecordingService.STATE_FULL) { startActivity(new Intent(RecordingActivity.this, SaveTrip.class)); } else { if (state == RecordingService.STATE_RECORDING) { isRecording = true; initTrip(); } //PAUSE or RECORDING... recordService.setListener(RecordingActivity.this); } } else { // First run? Switch to user prefs screen if there are no prefs stored yet SharedPreferences settings = getSharedPreferences("PREFS", 0); if (settings.getAll().isEmpty()) { showWelcomeDialog(); } } RecordingActivity.this.unbindService(this); // race? this says we no longer care // Before we go to record, check GPS status final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); } } }; // This needs to block until the onServiceConnected (above) completes. // Thus, we can check the recording status before continuing on. bindService(rService, sc, Context.BIND_AUTO_CREATE); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); //Google Map MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); setButtonOnClickListeners(); }
From source file:ch.ethz.coss.nervousnet.vm.sensors.LocationSensor.java
@TargetApi(23) public void startLocationCollection() { NNLog.d(LOG_TAG, "startLocationCollection "); if (locationManager == null) return;//from w w w .jav a2 s . c o m NNLog.d(LOG_TAG, "startLocationCollection2"); // getting GPS status isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); NNLog.d(LOG_TAG, "isGPSEnabled = " + isGPSEnabled); // getting network status isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); NNLog.d(LOG_TAG, "isNetworkEnabled = " + isNetworkEnabled); /////TODO: if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { setSensorState(NervousnetVMConstants.SENSOR_STATE_AVAILABLE_PERMISSION_DENIED); } else ////TODO: if (!isGPSEnabled && !isNetworkEnabled) { setSensorState(NervousnetVMConstants.SENSOR_STATE_AVAILABLE_PERMISSION_DENIED); NNLog.d(LOG_TAG, "Location settings disabled"); // no network provider is enabled Toast.makeText(mContext, "Location settings disabled", Toast.LENGTH_LONG).show(); } else { this.canGetLocation = true; // First get location from Network Provider if (isNetworkEnabled) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_TIME_BW_UPDATES, this); NNLog.d(LOG_TAG, "Network"); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { reading = new LocationReading(System.currentTimeMillis(), new double[] { location.getLatitude(), 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_TIME_BW_UPDATES, this); NNLog.d(LOG_TAG, "GPS Enabled"); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { reading = new LocationReading(System.currentTimeMillis(), new double[] { location.getLatitude(), location.getLongitude() }); } } } } dataReady(reading); } }
From source file:com.temboo.example.FoursquareConnectedActivity.java
/** * onCreate is called by Android when the activity is first created. *//*from w ww . j a v a 2 s . co m*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Initialize the UI with the "connected mode" layout (defined in /res/layout/foursquare_connected.xml) setContentView(R.layout.foursquare_connected); // Obtain a reference to the "current venue" textview currentVenueTextView = (TextView) findViewById(R.id.foursquareVenueField); // Initiate the Temboo session try { session = new MyTemboo(TEMBOO_APPKEY_NAME, TEMBOO_APPKEY); } catch (Exception e) { currentVenueTextView.setText("Uh-oh! Something has gone horribly wrong."); Log.e("TEMBOO", "Error starting Temboo session.", e); } // Debug: display the Fourquare Oauth token retrieved by FoursquareOauthActivity Toast.makeText(FoursquareConnectedActivity.this, "Successfully connected to Foursquare. Oauth token: " + FOURSQUARE_OAUTH_TOKEN, Toast.LENGTH_SHORT) .show(); // Obtain a reference to the Android LocationManager, which is (surprisingly) responsible for managing GPS/location data LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Get and store the last known location currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); // Register a listener with the Location Manager to receive location updates. Currently, this is configured // to request GPS updates every 3 minutes, with a minimum location-differential of 3 meters per update. // See http://developer.android.com/reference/android/location/LocationManager.html locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 180000, 3, new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } // When the location changes, store the current location in the parent activity @Override public void onLocationChanged(Location location) { currentLocation = location; } }); // Attach the "lookup location" button click handler Button lookupButton = (Button) findViewById(R.id.getVenue); lookupButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { getFoursquareVenueForCurrentLocation(); } catch (Exception e) { Log.e("TEMBOO", "Error performing Foursquare venue lookup", e); Toast.makeText(FoursquareConnectedActivity.this, "Error performing foursquare venue lookup! " + e.getMessage(), Toast.LENGTH_SHORT) .show(); } } }); // Attach the "Foursquare checkin" button click handler Button checkinButton = (Button) findViewById(R.id.doFoursquareCheckin); checkinButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { doFoursquareCheckin(); } catch (Exception e) { Log.e("TEMBOO", "Error performing Foursquare checkin", e); Toast.makeText(FoursquareConnectedActivity.this, "Error performing foursquare checkin! " + e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); }
From source file:com.nextgis.mobile.TrackerService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(MainActivity.TAG, "Received start id " + startId + ": " + intent); super.onStartCommand(intent, flags, startId); if (intent == null) return START_STICKY; String action = intent.getAction(); if (action == null) return START_STICKY; Log.d(MainActivity.TAG, "action " + action); if (action.equals(ACTION_STOP)) { trackerLocationListener.setWritePostion(false); if (dbHelper != null) dbHelper.close();//from w w w. jav a 2 s. c om if (!trackerLocationListener.isWriteTrack()) stopSelf(); } else if (action.equals(ACTION_STOP_GPX)) { m_TrakAddPointHandler = null; NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(mNotifyId); trackerLocationListener.StoreTrack(false); trackerLocationListener.setWriteTrack(false); if (!trackerLocationListener.isWritePostion()) stopSelf(); } else if (action.equals(ACTION_START)) { SharedPreferences prefs = getSharedPreferences(PreferencesActivity.SERVICE_PREF, MODE_PRIVATE | MODE_MULTI_PROCESS); boolean isStrarted = prefs.getBoolean(PreferencesActivity.KEY_PREF_SW_TRACK_SRV, false); if (isStrarted) { if (!trackerLocationListener.isWritePostion()) { trackerLocationListener.setWritePostion(true); dbHelper = new PositionDatabase(getApplicationContext()); PositionDB = dbHelper.getWritableDatabase(); long nMinDistChangeForUpdates = prefs .getLong(PreferencesActivity.KEY_PREF_MIN_DIST_CHNG_UPD + "_long", 25); long nMinTimeBetweenUpdates = prefs.getLong(PreferencesActivity.KEY_PREF_MIN_TIME_UPD + "_long", 0); Log.d(MainActivity.TAG, "start LocationManager MinDist:" + nMinDistChangeForUpdates + " MinTime:" + nMinTimeBetweenUpdates); Log.d(MainActivity.TAG, "start LocationManager.GPS_PROVIDER"); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, nMinTimeBetweenUpdates, nMinDistChangeForUpdates, trackerLocationListener); Log.d(MainActivity.TAG, "start LocationManager.NETWORK_PROVIDER"); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, nMinTimeBetweenUpdates, nMinDistChangeForUpdates, trackerLocationListener); Log.d(MainActivity.TAG, "request end"); } boolean bEnergyEconomy = prefs.getBoolean(PreferencesActivity.KEY_PREF_SW_ENERGY_ECO, true); long nMinTimeBetweenSend = prefs.getLong(PreferencesActivity.KEY_PREF_TIME_DATASEND + "_long", DateUtils.MINUTE_IN_MILLIS); ScheduleNextUpdate(this.getApplicationContext(), TrackerService.ACTION_START, nMinTimeBetweenSend, bEnergyEconomy, isStrarted); } } else if (action.equals(ACTION_START_GPX)) { SharedPreferences prefs = getSharedPreferences(PreferencesActivity.SERVICE_PREF, MODE_PRIVATE | MODE_MULTI_PROCESS); boolean isStrarted_GPX = prefs.getBoolean(PreferencesActivity.KEY_PREF_SW_TRACKGPX_SRV, false); if (isStrarted_GPX) { if (!trackerLocationListener.isWriteTrack()) { trackerLocationListener.setWriteTrack(true); long nMinDistChangeForUpdates = prefs .getLong(PreferencesActivity.KEY_PREF_MIN_DIST_CHNG_UPD + "_long", 25); long nMinTimeBetweenUpdates = prefs.getLong(PreferencesActivity.KEY_PREF_MIN_TIME_UPD + "_long", 0); Log.d(MainActivity.TAG, "start GPX LocationManager MinDist:" + nMinDistChangeForUpdates + " MinTime:" + nMinTimeBetweenUpdates); Log.d(MainActivity.TAG, "start GPX LocationManager.GPS_PROVIDER"); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, nMinTimeBetweenUpdates, nMinDistChangeForUpdates, trackerLocationListener); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this).addParentStack(MainActivity.class) .addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.record_start_notify) .setContentTitle(getString(R.string.app_name)).setOngoing(true) .setContentText(getString(R.string.gpx_recording)) .setContentIntent(resultPendingIntent); Notification noti = mBuilder.getNotification(); //noti.flags |= Notification.FLAG_FOREGROUND_SERVICE;//Notification.FLAG_NO_CLEAR | NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(mNotifyId, noti); } } boolean bEnergyEconomy = prefs.getBoolean(PreferencesActivity.KEY_PREF_SW_ENERGY_ECO, true); long nMinTimeBetweenSend = prefs.getLong(PreferencesActivity.KEY_PREF_TIME_DATASEND + "_long", DateUtils.MINUTE_IN_MILLIS); ScheduleNextUpdate(getApplicationContext(), TrackerService.ACTION_START_GPX, nMinTimeBetweenSend, bEnergyEconomy, isStrarted_GPX); } return START_STICKY; }