我的Android应用程序必须捕获MANUAL禁用蓝牙以避免欺诈。我使用以下代码,一些用户告诉我,任何蓝牙错误都会触发btTurnedOff()
。
...监听
public interface BtConnectionListener {
void btTurnedOff();
}
...接收器
public class BtConnectionReceiver extends BroadcastReceiver {
private final BtConnectionListener listener;
public BtConnectionReceiver(final BtConnectionListener listener) {
this.listener = listener;
}
@Override
public void onReceive(final Context context, final Intent intent) {
final String action = intent.getAction();
if (action != null && action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
switch (state) {
case BluetoothAdapter.STATE_TURNING_OFF:
listener.btTurnedOff();
break;
}
}
}
}
在我的主要服务中......
@Override
public void btTurnedOff() {
//Some stuff to penalize the fraud
}
任何人都知道我做错了什么?