BluetoothSocket.isConnected问题

时间:2017-05-05 11:31:53

标签: android bluetooth

我创建了一个Android应用程序,如果我的Android与我的计算机有蓝牙连接并关闭了我的电脑,isConnected仍然返回true。任何人都知道这是否可以修复?

我不确定是否有蓝牙心跳。

1 个答案:

答案 0 :(得分:1)

试试这个。

    IntentFilter connectivityFilter = new IntentFilter();
    connectivityFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
    connectivityFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    registerReceiver(bluetoothModeCheckingReceiver, connectivityFilter);



 private final BroadcastReceiver bluetoothModeCheckingReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
            // to do
        } else if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) {
           //  to do
        }
    }
};