0
我正在开发一个应用程序,它将使用ToggleButton来启用和禁用蓝牙。我设法让ToggelButton打开和关闭蓝牙,但我无法检查BlueTooth是否打开和关闭。问题是,如果您从其他位置开启或关闭蓝牙,则可以在实际打开时关闭蓝牙。这是我到目前为止的代码:蓝牙ToggleButton没有检查状态
public void onClick(View v) {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if(adapter != null) {
if(adapter.getState() == BluetoothAdapter.STATE_ON) {
adapter.disable();
} else if (adapter.getState() == BluetoothAdapter.STATE_OFF){
adapter.enable();
} else {
//State.INTERMEDIATE_STATE;
}
}
}
我怎样才能让蓝牙是开启和未选中蓝牙功能已关闭它进行检查?