user747858
user747858

Reputation:

How to receive location updates without using a service

Is there an alternative to running a service to receive location updates?

Upvotes: 3

Views: 2895

Answers (1)

Suchi
Suchi

Reputation: 10039

You could use a PendingIntent like this -

Intent intent = new Intent(CUSTOM_INTENT);
    LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    PendingIntent launchIntent = PendingIntent.getBroadcast(context, 5000, intent, 0);

    manager.requestLocationUpdates(selectProvider(), 0, 0, launchIntent);

Your broadcast receiver should have an intent filter for the CUSTOM_INTENT in the manifest file

Upvotes: 5

Related Questions