Receive A Notification (via Broadcastreceiver) When Gps (or Location Services) Is Started/stopped
Solution 1:
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
publicvoidonGpsStatusChanged(intevent) {
if(event==GpsStatus.GPS_EVENT_STARTED){
Log.d(TAG,"Gps Started");
}elseif(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.
Solution 2:
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.
Post a Comment for "Receive A Notification (via Broadcastreceiver) When Gps (or Location Services) Is Started/stopped"