Android 蓝牙对活动结果的影响

Android 蓝牙对活动结果的影响,android,bluetooth,Android,Bluetooth,您好,我正在进行一个项目,该项目要求用户启用蓝牙,一旦用户回答是,它将运行另一种方法连接到外部设备。但是,当蓝牙已启用时,该代码可以工作,但当必须要求用户启用蓝牙时,该代码不起作用 这是我的密码: 检查蓝牙状态 void findBTdevice() throws IOException { if(mBluetoothAdapter == null) { bluetoothStatus = "No bluetooth adapter available";

您好,我正在进行一个项目,该项目要求用户启用蓝牙,一旦用户回答是,它将运行另一种方法连接到外部设备。但是,当蓝牙已启用时,该代码可以工作,但当必须要求用户启用蓝牙时,该代码不起作用

这是我的密码:

检查蓝牙状态

void findBTdevice() throws IOException {


    if(mBluetoothAdapter == null)
    {
        bluetoothStatus = "No bluetooth adapter available";
    }


    if (mBluetoothAdapter.isEnabled()) {

    pairBTdevices();

    } else {
        Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBluetooth, 0);

    }
}
论活动结果

protected void onActivityResult(int requestCode, int resultCode, Intent Intent) {

    if (requestCode == 0) {
        if (resultCode == 0) {
            bluetoothStatus = "Bluetooth Required";

        } else {
            try {
                pairBTdevices();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
这是日志,如果有帮助的话

D/BluetoothUtils﹕ isSocketAllowedBySecurityPolicy start : device null
W/BluetoothAdapter﹕ getBluetoothService() called with no BluetoothManagerCallback
D/BluetoothSocket﹕ connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[63]}

你能详细解释一下它不起作用是什么意思吗?我的意思是它调用方法并似乎连接起来,但是UI变得一团糟,你让我在这里更加困惑。你说用户界面乱七八糟是什么意思?是不是到处都会突然出现闪烁的问候语?调用什么方法?配对设备?