我有一个带有按钮的应用程序,用于打开和关闭BT.我在那里有以下代码;
public void buttonFlip(View view) {
flipBT();
buttonText(view);
}
public void buttonText(View view) {
Button buttonText = (Button) findViewById(R.id.button1);
if (mBluetoothAdapter.isEnabled() || (mBluetoothAdapter.a)) {
buttonText.setText(R.string.bluetooth_on);
} else {
buttonText.setText(R.string.bluetooth_off);
}
}
private void flipBT() {
if (mBluetoothAdapter.isEnabled()) {
mBluetoothAdapter.disable();
} else {
mBluetoothAdapter.enable();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在调用按钮Flip,它会翻转BT状态,然后调用ButtonText,它应该更新UI.但是,我遇到的问题是,BT打开需要几秒钟 - 在这几秒钟内,BT状态未启用,使我的按钮说蓝牙关闭,即使它将在2秒内打开.
我STATE_CONNECTING在BluetoothAdapter android文档中找到了常量,但是......我根本就不知道如何使用它,成为一个新手和所有.
所以,我有两个问题: