Subscribe to ANCs on Android
Based on the services listed here, I am trying to subscribe to the service from an Android device, but I can't make the request part work properly. I try to advertise with 7905f431-b5ce-4e99-a40f-4b1e122d00d0, but the peripheral device is not displayed in the Bluetooth device list of iPhone. I also use (LE) scanning and filter to discover the ANCs server, but I have no luck. Any tips?
Editing: Codes
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 advertised services on the iPhone. However, after receiving the notification on the iPhone, the subscription notification will not trigger oncharacteristicchanged
Update2: all write descriptor.setvalue calls are successful and run in sequence
Update3: part of the code of this sample. Is used
Update4: test equipment: Nexus 5x Android 6.0.1; iPhone 6S iOS 10.3.1
Update5: BT log
Write request
Write reply
resolvent:
Oh, I have encountered a similar problem. Please ensure that local notifications are not used when testing on IOS, because these will not be propagated through ANCs. For any reason, you need real push notifications