Question

I tried an approach by using a BroadcastReceiver that listens for PROVIDERS_CHANGED action, but that only tells me when the location settings are turned on/off. I would like to know when the location services are being used to acquire a location by any application. I don't need to know which application is doing it, and I don't care for the location itself. I just want to know whenever some application tries to acquire a location, and when it stops doing that. Is this possible?

Was it helpful?

Solution

I don't know if you really need to be notified via broadcast receiver, but if it is not absolutely required then you can use GpsStatus.Listener :

Here is how to use it :

mLocationManager.addGpsStatusListener(new GpsStatus.Listener(){

    @Override
    public void onGpsStatusChanged(int event) {
        if(event==GpsStatus.GPS_EVENT_STARTED){
            Log.d(TAG,"Gps Started");
        }else if(event==GpsStatus.GPS_EVENT_STOPPED){
            Log.d(TAG,"Gps Stopped");
        }
    }
});

And if you really need to receive this info via BroadcastReceiver : just wrap this code in a Service and send the event from there.

OTHER TIPS

Not precisely what you asked for but might be of interest: you can register for location updates from PASSIVE_PROVIDER through LocationManager.

This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself.

You won't be able to know when other apps stop requesting new locations, or when they start exactly, but you'll know when they receive one that they have requested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top