List of usage examples for android.location LocationManager requestLocationUpdates
@UnsupportedAppUsage private void requestLocationUpdates(LocationRequest request, LocationListener listener, Looper looper, PendingIntent intent)
From source file:ca.ualberta.cs.cmput301w15t04team04project.FragmentEditClaim2.java
public void getClaimLocation(View view) { LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener); }
From source file:org.mozilla.mozstumbler.service.stumblerthread.scanners.GPSScanner.java
private void startPassiveMode() { LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (!isGpsAvailable(locationManager)) { return;/*w ww. j a v a 2s. com*/ } locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, this); final int timeDiffSec = Long.valueOf((System.currentTimeMillis() - mTelemetry_lastStartedMs) / 1000) .intValue(); if (mTelemetry_lastStartedMs > 0 && timeDiffSec > 0) { TelemetryWrapper.addToHistogram(AppGlobals.TELEMETRY_TIME_BETWEEN_STARTS_SEC, timeDiffSec); } mTelemetry_lastStartedMs = System.currentTimeMillis(); }
From source file:com.precisionag.waterplane.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.field); MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map); GoogleMap map = mapFragment.getMap(); map.setMapType(GoogleMap.MAP_TYPE_HYBRID); map.setMyLocationEnabled(true);/*from ww w. j a v a 2s . com*/ map.setOnMapClickListener(this); map.setOnMarkerClickListener(onMarkerClickListener); field = new Field(bitmap, new LatLng(0.0, 0.0), new LatLng(0.0, 0.0), 0.0, 0.0); markers = new ArrayList<Marker>(); mode = 0; readDataFile(field); prevoverlay = field.createOverlay(map); configSeekbar(field, prevoverlay); LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); }
From source file:ca.ualberta.cs.cmput301w15t04team04project.EditClaimActivity.java
/** *///from w w w.j a v a 2 s . c o m public void getClaimLocation(View view) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener); claimLocation = location; }
From source file:com.metinkale.prayerapp.compass.Main.java
@Override protected void onResume() { super.onResume(); mSensorManager.unregisterListener(mMagAccel); mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_GAME); if (mSelCity == null) { mSelCity = (TextView) findViewById(R.id.selcity); mSelCity.setOnClickListener(new OnClickListener() { @Override/* ww w . j av a 2s .c o m*/ public void onClick(View arg0) { if (App.isOnline()) { startActivity(new Intent(Main.this, LocationPicker.class)); } else { Toast.makeText(Main.this, R.string.noConnection, Toast.LENGTH_LONG).show(); } } }); } if (PermissionUtils.get(this).pLocation) { LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = locMan.getProviders(true); for (String provider : providers) { locMan.requestLocationUpdates(provider, 0, 0, this); Location lastKnownLocation = locMan.getLastKnownLocation(provider); if (lastKnownLocation != null) { calcQiblaAngel(lastKnownLocation); } } } if (Prefs.getCompassLat() != 0) { Location loc = new Location("custom"); loc.setLatitude(Prefs.getCompassLat()); loc.setLongitude(Prefs.getCompassLng()); calcQiblaAngel(loc); } }
From source file:com.jmstudios.redmoon.preference.LocationPreference.java
public void searchLocation(boolean explicitRequest) { if (mIsSearchingLocation) mIsSearchExplicit = explicitRequest || mIsSearchExplicit; else/*from www .java 2 s. c om*/ mIsSearchExplicit = explicitRequest; if (!mIsSearchingLocation) { if (DEBUG) Log.i(TAG, explicitRequest ? "Searching location on explicit request" : "Searching location automatically"); mIsSearchingLocation = true; LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationListener listener = new LocationUpdateListener(mContext, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener); } else { handleLocationSearchFailed(); } } if (mIsSearchExplicit && mIsSearchingLocation) { setSummary(mContext.getString(R.string.searching_location)); } }
From source file:com.jmstudios.redmoon.receiver.AutomaticFilterChangeReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (DEBUG)//from w w w .ja va 2 s. c om Log.i(TAG, "Alarm received"); FilterCommandSender commandSender = new FilterCommandSender(context); FilterCommandFactory commandFactory = new FilterCommandFactory(context); Intent onCommand = commandFactory.createCommand(ScreenFilterService.COMMAND_ON); Intent pauseCommand = commandFactory.createCommand(ScreenFilterService.COMMAND_PAUSE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SettingsModel settingsModel = new SettingsModel(context.getResources(), sharedPreferences); boolean turnOn = intent.getData().toString().equals("turnOnIntent"); if (turnOn) { commandSender.send(onCommand); cancelTurnOnAlarm(context); scheduleNextOnCommand(context); } else { commandSender.send(pauseCommand); cancelPauseAlarm(context); scheduleNextPauseCommand(context); // We want to dismiss the notification if the filter is paused // automatically. // However, the filter fades out and the notification is only // refreshed when this animation has been completed. To make sure // that the new notification is removed we create a new runnable to // be excecuted 100 ms after the filter has faded out. Handler handler = new Handler(); DismissNotificationRunnable runnable = new DismissNotificationRunnable(context); handler.postDelayed(runnable, ScreenFilterPresenter.FADE_DURATION_MS + 100); } if (settingsModel.getAutomaticFilterMode().equals("sun")) { // Update times for the next time (fails silently) LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationListener listener = new LocationUpdateListener(context); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener); } } }
From source file:com.metinkale.prayerapp.compass.Main.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mRefresh == item) { mOnlyNew = true;//www . j a va 2 s . com if (PermissionUtils.get(this).pLocation) { LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locMan.removeUpdates(this); List<String> providers = locMan.getProviders(true); for (String provider : providers) { locMan.requestLocationUpdates(provider, 0, 0, this); } } } else if (mSwitch == item) { if (mMode == Mode.Map) { mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME); mSensorManager.registerListener(mMagAccel, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), SensorManager.SENSOR_DELAY_GAME); updateFrag(Mode.TwoDim); mSwitch.setIcon(MaterialDrawableBuilder.with(this).setIcon(MaterialDrawableBuilder.IconValue.MAP) .setColor(Color.WHITE).setToActionbarSize().build()); } else if (PermissionUtils.get(this).pLocation) { mSensorManager.unregisterListener(mMagAccel); updateFrag(Mode.Map); mSwitch.setIcon(MaterialDrawableBuilder.with(this) .setIcon(MaterialDrawableBuilder.IconValue.COMPASS_OUTLINE).setColor(Color.WHITE) .setToActionbarSize().build()); } else { Toast.makeText(this, R.string.permissionNotGranted, Toast.LENGTH_LONG).show(); } } return super.onOptionsItemSelected(item); }
From source file:com.wikitude.example.ARBrowserActivity.java
/** Called when the activity is first created. */ @Override//from w w w. j a v a 2s. com public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // let the application be fullscreen this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // check if the device fulfills the SDK'S minimum requirements if (!ArchitectView.isDeviceSupported(this)) { Toast.makeText(this, "minimum requirements not fulfilled", Toast.LENGTH_LONG).show(); this.finish(); return; } setContentView(R.layout.main); // set the devices' volume control to music to be able to change the // volume of possible soundfiles to play this.setVolumeControlStream(AudioManager.STREAM_MUSIC); this.architectView = (ArchitectView) this.findViewById(R.id.architectView); // onCreate method for setting the license key for the SDK architectView.onCreate(apiKey); // in order to inform the ARchitect framework about the user's location // Androids LocationManager is used in this case // NOT USED IN THIS EXAMPLE // locManager = // (LocationManager)getSystemService(Context.LOCATION_SERVICE); // locManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, // 0, this); // Getting LocationManager object from System Service LOCATION_SERVICE LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // Creating a criteria object to retrieve provider Criteria criteria = new Criteria(); // Getting the name of the best provider String provider = locationManager.getBestProvider(criteria, true); // Getting Current Location Location location = locationManager.getLastKnownLocation(provider); locationManager.requestLocationUpdates(provider, 20000, 0, this); // Getting latitude of the current location fLat = location.getLatitude(); // Getting longitude of the current location fLng = location.getLongitude(); }
From source file:org.runnerup.tracker.component.TrackerGPS.java
@Override public ResultCode onConnecting(final Callback callback, Context context) { if (ContextCompat.checkSelfPermission(this.tracker, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { mWithoutGps = true;//from w w w. j ava 2s.c o m } try { LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); frequency_ms = Integer .valueOf(preferences.getString(context.getString(R.string.pref_pollInterval), "500")); if (!mWithoutGps) { String frequency_meters = preferences.getString(context.getString(R.string.pref_pollDistance), "5"); lm.requestLocationUpdates(GPS_PROVIDER, frequency_ms, Integer.valueOf(frequency_meters), tracker); mGpsStatus = new GpsStatus(context); mGpsStatus.start(this); mConnectCallback = callback; return ResultCode.RESULT_PENDING; } else { String list[] = { GPS_PROVIDER, NETWORK_PROVIDER, PASSIVE_PROVIDER }; mLastLocation = null; for (String s : list) { Location tmp = lm.getLastKnownLocation(s); if (mLastLocation == null || tmp.getTime() > mLastLocation.getTime()) { mLastLocation = tmp; } } if (mLastLocation != null) { mLastLocation.removeSpeed(); mLastLocation.removeAltitude(); mLastLocation.removeAccuracy(); mLastLocation.removeBearing(); } gpsLessLocationProvider.run(); return ResultCode.RESULT_OK; } } catch (Exception ex) { return ResultCode.RESULT_ERROR; } }