基于列出的这里服务,我试图订阅安卓设备上的服务,但无法让征集部分正常工作。试着用7905F431-B5CE-4E99-A40F-4B1E122D00D0做广告,但是外围设备没有出现在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:测试设备:Nexus5XAndroid6.0.1;iPhone 6S+ iOS 10.3.1
update5: BT日志
写入请求

写响应

发布于 2017-04-21 22:02:46
哦,我也遇到了类似的问题,请确保在iOS上测试时不要使用本地通知,因为这些通知不会通过ANCS传播。无论出于什么原因,你都需要真正的推送通知。
发布于 2017-04-20 03:08:08
最近我遇到了一个类似的问题。为了解决这个问题,我所做的就是在我的BluetoothGatt中添加一个BluetoothGatt。我的setCharacteristicNotification现在看起来是这样的:
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
}也许,如果您能够发布/链接您的代码,我将能够进一步诊断您的确切问题,但上面的代码是我的问题的解决方案。
https://stackoverflow.com/questions/43461544
复制相似问题