android - BluetoothSocket.isConnected 问题

标签 android bluetooth

我已经创建了一个 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/

相关文章:

android - 各种安卓模拟器

android - 我如何在适用于 Android 的 Google Play Billing 中获取有关应用内购买的信息

android - 检查网络共享 USB/蓝牙是否处于 Activity 状态

c - 用于蓝牙传输的 Ruby 字符数组到字节数组(十六进制字符)

android - 无法在 2 设备蓝牙 android 之间建立连接

android - 如何在屏幕固定时通过 NFC 发送字符串?

android - 通过 Uri 滑动加载本地镜像。

android - 如何让边框更平滑

android - listenUsingRfcommWithServiceRecord(字符串名称,UUID uuid)不工作

android - 在 BLE 中随机化 Mac 地址