Evan R.
Evan R.

Reputation: 1244

Does locationManager.addProximityAlert require a location listener

As the subject says, I've looked at the Android developer guide, and can't really find the answer. If you only want to know when you enter an area, does the Proximity alert require a location listener? I'm setting up the proximity alert as follows:

private void addProximityAlert(double latitude, double longitude) {

        Intent intent = new Intent(PROX_ALERT_INTENT);
        PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0,
                intent, 0);

        locationManager.addProximityAlert(latitude, longitude, POINT_RADIUS,
                PROX_ALERT_EXPIRATION, proximityIntent);

        IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
        proxalert = new ProximityIntentReceiver();
        registerReceiver(proxalert, filter);
    }

This then gets called as follows:

addProximityAlert(SMASH_LAT, SMASH_LNG);

The question is though, do I need the following?

locationManager.requestLocationUpdates(
                // check every 10 minutes
                low.getName(), MINIMUM_TIME_BETWEEN_UPDATE,
                MINIMUM_DISTANCECHANGE_FOR_UPDATE, new MyLocationListener());


public class MyLocationListener implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            Location pointLocation = retrievelocation();
            float distance = location.distanceTo(pointLocation);
            // txted.setText("Distance: " + distance);
        }

        @Override
        public void onStatusChanged(String s, int i, Bundle b) {
        }

        @Override
        public void onProviderDisabled(String s) {
            // try switching to a different provider
        }

        @Override
        public void onProviderEnabled(String s) {
            // try switching to a different provider
        }
    }

Or does the locationmanager already handle location updates from network/gps, and then know when it's in the proximity area?

Upvotes: 2

Views: 945

Answers (1)

Evan R.
Evan R.

Reputation: 1244

Nevermind, you do need it, but it can remain empty.

Upvotes: 1

Related Questions