I m trying to register a broadcast receiver to receive updates when gps status is changed.
However, my GpsChangeReceiver onReceive method doesn't seem to be called when gps status is changed from enabled to disabled or vice-versa.
First of all, i'm registering the reciever:
GpsChangeReceiver m_gpsChangeReceiver = new GpsChangeReceiver();
this.registerReceiver(m_gpsChangeReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
Then, I have my GPS Receiver
public class GpsChangeReceiver extends BroadcastReceiver
{
@Override
public void onReceive( Context context, Intent intent )
{
final LocationManager manager = (LocationManager) context.getSystemService( Context.LOCATION_SERVICE );
if (manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
//do something
}
else
{
//do something else
}
}
}
Finally, my manifest contains:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Can anyone see why the gps receiver is never called when I modify its status from the phone's settings??
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…