简体   繁体   English

用于在设备上发布辅助ble服务的API(外围模式)

[英]API for advertising secondary ble service on device(Peripheral mode)

From the docs ,it seems there are two types of ble(Bluetooth Low Energy)services-Primary and Secondary.A secondary service is included in a primary service ,kind of nesting a service inside other service.However I didnt find any api to create a secondary service and advertise it. 文档中看 ,似乎有两种类型的ble(蓝牙低能耗)服务:主服务和辅助服务主服务中包含辅助 服务 ,有点像将服务嵌套在其他服务中。但是我没有找到要创建的任何api辅助服务并进行宣传。

Whenever we use the following code for advertising a service,the service gets added as primary service. 每当我们使用以下代码来宣传一项服务时,该服务即被添加为主要服务。

 new AdvertiseData.Builder()
               // .setIncludeDeviceName(true)
                .addServiceUuid(new ParcelUuid(DeviceProfile.SERVICE_UUID))

Is there a way to specify the type of service, when advertising it?I have being trying to build an app to advertise a secondary service and a client app which will connect to this secondary service and read data.Please let me know if anyone know a workaround to do it.I have done lot of research but could not find anything. 广告发布时,有没有一种方法可以指定服务的类型?我正在尝试构建一个应用程序来发布辅助服务和一个客户端应用程序,以连接到该辅助服务并读取数据。如果有人知道,请告诉我我已经做了很多研究,但找不到任何东西。

Thanks in advance. 提前致谢。

After Successfully advertising you can do this: 成功刊登广告后,您可以执行以下操作:

BluetoothGattService service = new BluetoothGattService(serviceUUID,BluetoothGattService.SERVICE_TYPE_SECONDARY);
    service.addCharacteristic(characteristic);
    mGattServer.addService(service);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM