简体   繁体   中英

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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