我正试图注册一个广播接收器,以便在GPS状态更改时接收更新。
然而,我的GpsChangeReceiver的onReceive方法似乎不会在从启用到禁用或反之间更改GPS状态时被调用。
首先,我正在注册接收器:
GpsChangeReceiver m_gpsChangeReceiver = new GpsChangeReceiver();
this.registerReceiver(m_gpsChangeReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
然后,我有了我的GPS接收器
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
}
}
}
最后,我的清单包含:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
有人能看出来为什么我从手机的设置中修改GPS接收器的状态时,它从未被调用吗?