1

I am calling requestLocationUpdates with a PendingIntent. Later I want to know whether this request is still active. How can I do this?

I know whether I have called removeLocationUpdates but I expect there could be other ways that location updates can stop and I don't want to be wrong.

This question is not about geofences.

cja
  • 9,512
  • 21
  • 75
  • 129

1 Answers1

1

According to:

http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html

If you are looking for geofences:

static List<Geofence>    getTriggeringGeofences(Intent intent)
Returns a list of geofences that triggers this geofence transition alert.

Otherwise:

No, you cannot ask in a generic manner. That said if you have a listener, there are several methods of interest:

boolean  isConnectionCallbacksRegistered(GooglePlayServicesClient.ConnectionCallbacks listener)
Returns true if the specified listener is currently registered to receive connection events.


   boolean   isConnectionFailedListenerRegistered(GooglePlayServicesClient.OnConnectionFailedListener listener)
    Returns true if the specified listener is currently registered to receive connection failed events.

    void     registerConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks listener)
    Registers a listener to receive connection events from this GooglePlayServicesClient.

    void     registerConnectionFailedListener(GooglePlayServicesClient.OnConnectionFailedListener listener)

    Registers a listener to receive connection failed events from this GooglePlayServicesClient.

All of those will tell you about your specific listener. I don't see any code which would generically answer the question "Do you have anyone listening to you about anything"?

You could probably use introspection to force the API to make some of it's internals visible, but you can probably accomplish the thing you want some other, less ugly, way.

What are you trying to accomplish?

EDITS:

From the docs as well:

public void requestLocationUpdates (LocationRequest request, PendingIntent callbackIntent)

Requests location updates with a callback on the specified PendingIntent.

This method is suited for the background use cases, more specifically for receiving location updates, even when the app has been killed by the system. In order to do so, use a PendingIntent for a started service. For foreground use cases, the LocationListener version of the method is recommended, see requestLocationUpdates(LocationRequest, LocationListener).

Any previous LocationRequests registered on this PendingIntent will be replaced.

What's this mean?

1) Your request is staged, and won't be unstaged, until you explicitely call

public void removeLocationUpdates (PendingIntent callbackIntent)

2) This is true even when your app has been killed by the system. (assuming the background use case. I'm not sure on the foreground use case).

3) If the LocationClient has stopped receiving updates - your intent won't be notified of that. You would have to call:

isConnected() Checks if the client is currently connected to the service, so that requests to other methods will succeed. boolean
isConnecting() Checks if the client is attempting to connect to the service.

Location updates are sent with a key of KEY_LOCATION_CHANGED and a Location value on the intent.

Parameters request The location request for the updates. callbackIntent A pending intent to be sent for each location update.

So that later point - I would check to see if the LocationClient is connected/connecting. If not it's safe to assume that your Intent won't be fired - although it is still registered. Once you get connected again your Intent SHOULD still be registered.

Nathaniel D. Waggoner
  • 2,856
  • 2
  • 19
  • 41