2017-03-02 65 views
2

我正在BLE 4.2设备上运行具有自定义特征的自定义服务。我正在研究一个android应用程序来读取/写入特征等。我尝试的第一件事是读取特征。Android BLE服务缺失特征

我定义了一个UUID列表: List chars = new ArrayList <>();

我使用我知道的服务创建服务UUID: mCustomService = mBluetoothGatt.getService(MY_SERVICE_UUID);

我加载列表与4知道,从我服务的UUID:

chars.clear(); 
chars.add(UUID1); 
chars.add(UUID2); 
chars.add(UUID3); 
chars.add(UUID4); 

I read the first characteristic from the end of my list: 
BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(chars.get(chars.size() - 1)); 
    if(mReadCharacteristic != null) 
     mBluetoothGatt.readCharacteristic(mReadCharacteristic); 

mReadCharacteristic始终返回null,该服务不包含我的特点。

如果我使用BLE“嗅探器”应用程序,那么我会看到所有的特征。

感谢

丰富

PS我不能在这里找出格式!

回答

0

我有一个类似的设置 - 具有自定义服务和特征的设备 - 虽然设备是BLE 4.0。在你的应用程序,或许你正在做这件事,但这个问题不提它 - 但你叫

mBluetoothGatt.discoverServices();

这然后触发回调onServicesDiscovered。我在onServicesDiscovered处理程序中有类似的代码,它工作正常。

public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // getService // getCharactistics } // etc. }