gpt4 book ai didi

android - BluetoothSocket.isConnected 问题

转载 作者:行者123 更新时间:2023-11-30 00:33:36 24 4
gpt4 key购买 nike

我已经创建了一个 Android 应用程序,如果我的 Android 有一个蓝牙连接到我的电脑并且我关闭了我的电脑,isConnected 仍然返回 true。有人知道这是否可以修复吗?

不知道有没有蓝牙心跳

最佳答案

试试这个。

    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
}
}
};

关于android - BluetoothSocket.isConnected 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43803884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com