my application perform periodic location updates and Activity recognition detection in background.
I'm doing that using the Google Play Services API's:
for example - to register to location updates, I provide pending intent to receive update:
mLocationClient.requestLocationUpdates(mLocationRequest, pendingInent);
to unregister to location update, I'm doing the following:
mLocationClient.removeLocationUpdates(pendingInent);
that's nice, and working great.
but how can I find out if there is currently a pendingIntent holding Intent to my application's component is currently registered in front of Google play services to receive location updates or not?
I notices that there is no API to check this, and the approach to check for pendingIntent existence seems not to work for API's against google play services - the pending intent stays exists even after I call the removeLocationUpdates() method.
I know I can save state (to shared preferences) indicating if now I'm registered or not, but it's not the right solution, and will be "buggy" because it can happen that google play process went down, lost the pendingIntent, but my process will still think that the location updates are "active"..
same problem exactly exists for the activity recognition updates.
Just to make it clear, all I want to do is provide to the users of my application ability to know if my app is currently collecting data in background or not, and provide them a way to toggle between that. So if there is other way to do that in reliable way - I'll except it as an answer also
reliable way = knowing if currently the pending intent really registered in from of google play services...
- using
LocationListeneris not an option for me, because I must be able to receive updates event when my process is shout down - what's possible only usingPendingIntentcallback..
Thanks in advance.
UPDATE
this is the pendintIntent I provide to register and unregister to location updates:
Intent locationUpdatesIntent = new Intent(context, LocationUpdatesIntentService.class);
PendingIntent pendingInent = PendingIntent.getService(context, 0, locationUpdatesIntent, PendingIntent.FLAG_UPDATE_CURRENT);
and this is how I'm trying to check (unsuccessfully) if it registered or not:
Intent locationUpdatesIntent = new Intent(context, LocationUpdatesIntentService.class);
PendingIntent pendingInent = PendingIntent.getService(context, 0, locationUpdatesIntent, PendingIntent.FLAG_NO_CREATE);
boolean isLocationUpdatesEnabled = (pendingIntent != null);
isLocationUpdatesEnabled returns true event after I call removeLocationUpdates()