Android BLE onCharacteristicRead和onCharacteristicChanged从未调用过

我正在尝试连接蓝牙LE温度计.连接到设备工作正常.让我兴奋的唯一部分是gattCallBack,它是onCharacteristicChanged / Read. ‘setNotification’和描述符’setValue’和’writeDescriptor’都返回true.永远不会调用onCharacteristicChanged来返回值.

我在Play商店使用了一个名为BLE Scanner的非常方便的小程序来帮助我向我提供有关该设备及其服务和特性的更多信息.

这就是为什么我只是硬编码服务2,特征0.我只是无法弄清楚为什么在我写writeDescript后,我从来没有看到任何回来.有趣的是,我可以使用其他一些特性(一个是温度间隔),我确实收到了一个响应(虽然数据是乱码.)

另外,出于好奇,为什么这个特征有两个描述符?

此代码包含在我的MainActivity方法中.不确定这是否会有所作为.我已经看过并尝试了几种方法,但没有运气.

private final BluetoothGattCallback gattCallback = new BluetoothGattCallback()
{
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt,int status,int newState)
    { ... }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt,int status)
    {
        mGatt = gatt;

        List<BluetoothGattService> services = mGatt.getServices();
        Log.i("onServicesDiscovered",services.toString());

        BluetoothGattCharacteristic characteristic = services.get(2).getCharacteristics().get(0);

        mGatt.setCharacteristicNotification(characteristic,true);

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

        mGatt.writeDescriptor(descriptor);

    }            

    @Override
    public void onCharacteristicRead(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status)
    { ... }

    @Override
    public void onCharacteristicChanged(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic)
    { ... }
};

更新:
我决定检查onDescriptorWrite方法并记录一些信息.

@Override            
public void onDescriptorWrite(BluetoothGatt gatt,BluetoothGattDescriptor descriptor,int status)
    {
        Log.i("descriptorWRITE",Integer.toString(status));
    }

有趣的是,状态返回13,即“写入操作超过属性的最大长度”.

我将进一步研究这个问题.

解决方法

我在这里发现了问题.我假设温度计正在使用标准的BLE服务和特性设置.它不是.他们创造了自己的自定义特征.一旦我切换到那个特性,’改变’方法开始射击.

相关文章

ADB Remote ATV Android TV 的遥控器,基于 ADB Shell 命令 ...
使用Flutter自带的SearchDelegate组件实现搜索界面,通过魔改...
上篇文章讲解了怎么使用Kotlin的协程配合Retrofit发起网络请...
安卓开发——WebView+Recyclerview文章详情页,解决高度...
Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...