android cs,在Android上订阅ANCS

根据here列出的服务,我试图订阅来自Android设备的服务,但无法让请求部分工作。尝试使用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 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上宣传的服务后找到服务和特征。但是,在iPhone上收到通知后,订阅通知不会触发onCharacteristicChanged。

update2:所有写入的descriptor.setValue调用都成功,并依次运行。

update3:使用来自this sample.的部分代码

update4:测试设备:Nexus 5X And​​roid 6.0.1; iPhone 6S + iOS 10.3.1

update5:BT日志

写请求

77816f82cd59313de552a5d1df52f48d.png

写回应

15b61d1632afee4b303bb973794b4a3e.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值