На основе перечисленных служб здесь, я пытаюсь подписаться на услугу с устройства Android, но не могу заставить работать часть запроса. Пытался рекламировать с помощью 7905F431-B5CE-4E99-A40F-4B1E122D00D0
, но периферийное устройство не отображается в списке Bluetooth-устройств iPhone. Также играл со сканированием (LE) и фильтрами, чтобы обнаружить сервер ANCS без везения. Любой намек?
редактировать: код
BleService.java
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
boolean enabled) {
Log.d(TAG, "setCharacteristicNotification");
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.DESCRIPTOR));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor)
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
}
}
SampleGattAttributes.java
public class SampleGattAttributes {
public static String ANCS_SERVICE = "7905F431-B5CE-4E99-A40F-4B1E122D00D0";
public static String NOTIFICATION_SOURCE = "9FBF120D-6301-42D9-8C58-25E699A21DBD";
public static String DATA_CONTROL = "22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB";
public static String DESCRIPTOR = "00002902-0000-1000-8000-00805f9b34fb";
}
MainActivity.java
private void displayServices(List<BluetoothGattService> services) {
for (BluetoothGattService service : services) {
if (service.getUuid().compareTo(UUID.fromString(ANCS_SERVICE)) == 0) {
for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
Log.d(TAG, "charac: " + characteristic.getUuid());
for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
Log.d(TAG, "desc: " + descriptor.getUuid());
}
if (characteristic.getUuid().compareTo(UUID.fromString(NOTIFICATION_SOURCE)) == 0) {
bleService.setCharacteristicNotification(characteristic, true);
}
}
}
}
}
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (BleService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
displayServices(bleService.getSupportedGattServices());
}
}
};
обновление: я могу найти службы и характеристики после подключения к службе, рекламируемой на iPhone. Однако подписка на уведомления не вызывает onCharacteristicChanged
при получении уведомления на iPhone.
update2: все вызовы записи descriptor.setValue
успешны и выполняются последовательно.
update3: использована часть кода из этого примера.
update4: тестовые устройства: Nexus 5X Android 6.0.1; iPhone 6S+ iOS 10.3.1
update5: журналы BT