Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
BLE设备自动与Android设备断开连接。安卓BLE_Android_Bluetooth_Bluetooth Lowenergy_Android 4.4 Kitkat_Android 4.3 Jelly Bean - Fatal编程技术网

BLE设备自动与Android设备断开连接。安卓BLE

BLE设备自动与Android设备断开连接。安卓BLE,android,bluetooth,bluetooth-lowenergy,android-4.4-kitkat,android-4.3-jelly-bean,Android,Bluetooth,Bluetooth Lowenergy,Android 4.4 Kitkat,Android 4.3 Jelly Bean,我正在使用Android Nexus 7通过蓝牙低能量链接连接设备。我可以连接设备,如果我没有与设备进行任何通信,我可以保持连接 但是,如果我通过单击按钮启用一个特定特征的通知,那么设备将在几秒钟的数据传输后与平板电脑断开连接 有人知道可能是什么问题吗?多谢各位 这是我的密码: public boolean setCharacteristicNotification(boolean enabled){ if (mBluetoothAdapter == null || mBl

我正在使用Android Nexus 7通过蓝牙低能量链接连接设备。我可以连接设备,如果我没有与设备进行任何通信,我可以保持连接

但是,如果我通过单击按钮启用一个特定特征的通知,那么设备将在几秒钟的数据传输后与平板电脑断开连接

有人知道可能是什么问题吗?多谢各位

这是我的密码:

    public boolean setCharacteristicNotification(boolean enabled){

      if (mBluetoothAdapter == null || mBluetoothGatt == null) {
          Log.w(TAG, "BluetoothAdapter not initialized");
               return false;      
      }

      BluetoothGattService Service = mBluetoothGatt.getService(UUID_MY_SERVICE);
      if (Service == null) {
          Log.e(TAG, "service not found!");
          return false;
      }

      BluetoothGattCharacteristic characteristic = Service.getCharacteristic(UUID_MY_CHARACTERISTIC);

      final int charaProp = characteristic.getProperties();

      if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
          mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

            BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
                    UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); 

            mBluetoothGatt.writeDescriptor(descriptor);

          return true;
      }

    return false;

}
(在问题编辑中回答。转换为社区wiki答案。请参阅)

OP写道:

我今天解决了这个问题

只需更改描述符.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)

descriptor.setValue(蓝牙GATTdescriptor.ENABLE_指示_值)

后续行动:

在我做了一些研究和测试之后,我发现自动断开连接的问题与Nexus7上蓝牙和WIFI之间的干扰有关。如果我关闭了WIFI,那么蓝牙的断开问题就消失了。这个问题并没有发生在星系3,4,5上


问题:我在特易购Hudl 2上也遇到了同样的问题,如果我传输一些的话 数据蓝牙一旦连接,就会断开连接。

解决方案:等待几分钟
连接后几秒钟,它似乎工作正常。

@Brain:在应用此功能之前,每个特征都会持续一段时间,然后它会自行断开连接。更改后,即使是单一特征也不会通知单一时间,并在同一时间断开连接。@Brain:我已尝试从android应用程序连接mac。但其未连接,并且每次都将处于断开状态。状态代码为133。但设备将配对。