Based on the services listed here , I am trying to subscribe to the service from an Android device, but cannot get the working part. Tried to advertise with 7905F431-B5CE-4E99-A40F-4B1E122D00D0, but the peripheral device does not appear in the device list of Bluetooth devices Bluetooth. It also plays with (LE) scans and filters to discover an ANCS server without any luck. Any hint?
edit: code
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());
}
}
};
update: I can find the services and features after connecting to the service advertised on the iPhone. However, a subscription to notifications does not call onCharacteristicChangedafter receiving a notification on the iPhone.
update2: all write calls descriptor.setValuesucceed and execute sequentially.
update3: uses part of the code from this example.
update4: : Nexus 5X Android 6.0.1; iPhone 6S + iOS 10.3.1
update5: BT

