Bluetooth Low Energy デバイスを接続するために、Samsung ACE3 でアプリを開発しています。Samsung は ACE3 を Android 4.3 にアップグレードすることを望んでいないため、Samsung ble API を使用する必要があります。現在、接続、データの読み取り、データの送信、および 1 つの特性からの通知の取得はすべて問題ありません。しかし、複数の特性の通知を有効にすると、最初に有効になった特性だけが通知を受け取ることができます。誰も同じ問題を抱えていますか?あなたの助けに感謝!
次のコードは、接続時に通知を有効にします
if (mBluetoothGatt != null && device != null) {
BluetoothGattService pucService = mBluetoothGatt.getService(device, PROFILE_UART_CONTROL_SERVICE);
if (pucService == null) {
showMessage("PUC service not found!");
return;
}
BluetoothGattCharacteristic motion = pucService.getCharacteristic(MOTION_READ);
if (motion == null) {
showMessage("charateristic not found!");
return;
}
enableNotification(true, motion);
BluetoothGattCharacteristic voltage = pucService.getCharacteristic(VOLTAGE_READ);
if (voltage == null) {
showMessage("charateristic not found!");
return;
}
enableNotification(true, voltage);
BluetoothGattCharacteristic pressure = pucService.getCharacteristic(PRESSURE_READ);
if (pressure == null) {
showMessage("charateristic not found!");
return;
}
enableNotification(true, pressure);
}
enableNotification メソッドは次のとおりです。
public boolean enableNotification(boolean enable, BluetoothGattCharacteristic characteristic) {
if (mBluetoothGatt == null)
return false;
if (!mBluetoothGatt.setCharacteristicNotification(characteristic, enable))
return false;
BluetoothGattDescriptor clientConfig = characteristic.getDescriptor(CCC);
if (clientConfig == null)
return false;
if (enable) {
Log.i(TAG,"enable notification");
clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
} else {
Log.i(TAG,"disable notification");
clientConfig.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
}
return mBluetoothGatt.writeDescriptor(clientConfig);
}