Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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
Android BLE:未调用onCharactersticChanged_Android_Bluetooth Lowenergy_Android Bluetooth_Bluetooth Gatt_Samsung Galaxy - Fatal编程技术网

Android BLE:未调用onCharactersticChanged

Android BLE:未调用onCharactersticChanged,android,bluetooth-lowenergy,android-bluetooth,bluetooth-gatt,samsung-galaxy,Android,Bluetooth Lowenergy,Android Bluetooth,Bluetooth Gatt,Samsung Galaxy,我有一个关于Android的问题。具体如下: 此问题发生在三星Galaxy S10e、Android 10、OneUI 2.5上。当智能手机连接到某个Wifi时,它就会出现。如果智能手机连接到Wifi,则不会调用onCharacteristic Changed。如果关闭Wifi,一切正常,并调用onCharacteristicChanged。它还测试了谷歌像素3XL。使用这款智能手机,无论是否连接到Wifi,一切都能正常工作。这似乎发生在新的OneUI版本2.5之后。它在OneUI2.1上按预期

我有一个关于Android的问题。具体如下: 此问题发生在三星Galaxy S10e、Android 10、OneUI 2.5上。当智能手机连接到某个Wifi时,它就会出现。如果智能手机连接到Wifi,则不会调用onCharacteristic Changed。如果关闭Wifi,一切正常,并调用onCharacteristicChanged。它还测试了谷歌像素3XL。使用这款智能手机,无论是否连接到Wifi,一切都能正常工作。这似乎发生在新的OneUI版本2.5之后。它在OneUI2.1上按预期工作。BluetoothGatt上的SetCharacteristicNotification和writeDescriptor工作正常,writeDescriptor(描述符)返回true。所以我不认为这段代码有什么问题,因为它在关闭Wifi时可以正常工作。就本例而言,以下是我在Android BLE上启用通知的代码:

val CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
characteristic?.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
bg?.setCharacteristicNotification(characteristic, true)
val descriptor = characteristic?.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID)
descriptor?.value = if (enabled) BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE else byteArrayOf(0x00, 0x00)
descriptor?.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE)
bg?.writeDescriptor(descriptor) ?: false
我已经在没有行
描述符?.setValue(BluetoothGattDescriptor.ENABLE\u INDICATION\u VALUE)
的情况下尝试过了。这不会改变任何事情。 我有什么遗漏吗?为什么Wifi连接块的特性会改变?如果智能手机已打开Wifi且未连接,则它可以工作。只有当Wifi打开并连接时,它才起作用

WriteCharacteristic和ReadCharacteristic工作正常,无论是否连接Wifi,都会触发回调。因此,BluetoothGattCallback设置得很好

有人能帮我吗?谢谢

最好的,
Markus

您是否总是在设备连接后编写描述符?您可以在
BluetoothGattCallback
中的
onDescriptorWrite()
方法中检查
writeDescriptor
操作的结果。我想当您编写描述符时,您的设备可能尚未连接,并且由于它,通知未启用。感谢您的回复Sergey。我可以检查你的建议,但如果是这种情况,并且我还没有连接到设备,那么行
bg?.writeDescriptor(descriptor)?:false
应该返回false,对吗?这确实是真的。而且,我只在发现某个服务和某个特性时才启动此操作。我只在设备连接后才开始寻找服务。所以逻辑顺序应该是正确的。。。连接->连接->发现服务->获取特征->找到特征->启用通知我检查了onDescriptorWrite()的结果:它被调用,状态为GATT_SUCCESS(=0)。看来这是对的。打开Wifi时仍无法调用onCharacteristicChanged。您是否总是在设备连接后编写描述符?您可以在
BluetoothGattCallback
中的
onDescriptorWrite()
方法中检查
writeDescriptor
操作的结果。我想当您编写描述符时,您的设备可能尚未连接,并且由于它,通知未启用。感谢您的回复Sergey。我可以检查你的建议,但如果是这种情况,并且我还没有连接到设备,那么行
bg?.writeDescriptor(descriptor)?:false
应该返回false,对吗?这确实是真的。而且,我只在发现某个服务和某个特性时才启动此操作。我只在设备连接后才开始寻找服务。所以逻辑顺序应该是正确的。。。连接->连接->发现服务->获取特征->找到特征->启用通知我检查了onDescriptorWrite()的结果:它被调用,状态为GATT_SUCCESS(=0)。看来这是对的。当Wifi打开时,仍然无法调用onCharacteristicChanged。