0

I have seen the following question asked many times but none of the answers have been very clear, at least to me....

I want my android app to capture when GPS is enabled/disabled. I am NOT interested in the users current location, or in receiving location updates.

The reason I am confused is people have suggested both a location listener and the gpsstatus listener and I'm not sure how to work with either (I have looked at tutorials such as http://www.vogella.com/tutorials/AndroidLocationAPI/article.html and on androidhive etc.).

1)Do I implement the location listener within a service? If so, how is onProviderEnabled or onProviderDisabled called? Should the listener be created in onCreate(), onStartCommand() or does it matter?

2)Do I need to implement my service in conjunction with a broadcast receiver like you do for screen on/off events? Or can I capture the events with just a service...

3) If I don't care about location updates, do I still have to call locationManager.requestLocationUpdates in order for onProviderEnabled and onProviderDisabled to be called?

Edit: It needs to work on android api 8+

idunno
  • 713
  • 3
  • 10
  • 25
  • 1
    have you checked out this question? http://stackoverflow.com/questions/6368286/detecting-gps-on-off-switch-in-android-phones – stamanuel Feb 17 '14 at 15:48
  • I did, thanks, but I need to support android api 8 and up, that solution will only work for api 9+ :( – idunno Feb 17 '14 at 15:55
  • 2
    Android 2.2 (API Level 8) [represents <1.3% of Android devices as of February 2014](https://developer.android.com/about/dashboards/index.html). The solution suggested in the above comment is the right one to use for API Level 9+. **Please use that solution** for such devices, as the techniques you describe in your question are user-hostile (wasting RAM) and intrinsically unreliable (as users desperately try to reclaim their RAM from those who waste it). If, after you have the API Level 9+ solution working, you want to do something else **just** for API Level 8, worry about that then. – CommonsWare Feb 17 '14 at 16:07

0 Answers0