我有一个接收器,如果用户改为飞行模式,我想作出反应,但目前我的应用程序中永远不会调用它。我的代码将收到另一个ACTION_STATE_CHANGE。有什么想法吗?
private final BroadcastReceiver btReceiver = new BroadcastReceiver() {
private de.srs.android.pdixuploader.util.Settings penSettings;
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equalsIgnoreCase(BluetoothAdapter.ACTION_STATE_CHANGED)){
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
switch(state){
case BluetoothAdapter.STATE_OFF:
stopSDK();
break;
case BluetoothAdapter.STATE_ON:
startSDK( new de.srs.android.pdixuploader.util.Settings(false, false));
break;
}
}
if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)){
Log.d(TAG, "airplane mode changed");
}
}
};
接收方将在我的服务的onCreate方法
中注册@Override
public void onCreate() {
super.onCreate();
appData = (AttachApplication) getApplication();
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(btReceiver, filter);
}