adev
adev

Reputation: 377

Configure manifest to catch a new location available

How can I configure the manifest in order to chatch new location coordinates? Can I use the BroardcastReceiver to catch new coordinates?

Upvotes: 0

Views: 197

Answers (2)

Kuffs
Kuffs

Reputation: 35661

If I understand the question correctly, you may find the passive provider helpful.

Helpful

Upvotes: 0

Damian
Damian

Reputation: 8072

If you add this within the application element of your manifest it will call onReceive in your LocationChangedReceiver class whenever a new gps coordinate is obtained:

<receiver android:name=".location.LocationChangedReceiver" />

LocationChangedReceiver might look like this:

public class LocationChangedReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String locationKey = LocationManager.KEY_LOCATION_CHANGED;

        if (intent.hasExtra(locationKey)) {
            Location location = (Location) intent.getExtras().get(locationKey);
            Log.d(TAG, "Got Location! Lat:" + location.getLatitude() + ", Lon:" + location.getLongitude() + ", Alt:" + location.getAltitude() + ", Acc:" + location.getAccuracy());

            return;
        }

    }
}

Upvotes: 1

Related Questions