如何在android中宣传蓝牙LE服务UUID?

时间:2014-07-01 06:32:38

标签: android bluetooth-lowenergy android-bluetooth

我想连接两台具有低能量蓝牙的Android手机,因此我在服务UUID中创建了一个特色UUID。一部手机将广告服务uuid​​,另一部手机将扫描服务uuid​​,但是,我不知道如何宣传服务uuid​​。请指导我如何完成任务。这是我的示例代码。

UUID serviceUUID = UUID.randomUUID();
UUID characteristicUUID = UUID.randomUUID();
UUID descriptorUUID = UUID.randomUUID();


BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(characteristicUUID, BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ);
characteristic.setValue(77, BluetoothGattCharacteristic.FORMAT_UINT8, 0);

BluetoothGattDescriptor descriptor = new BluetoothGattDescriptor(descriptorUUID,     BluetoothGattDescriptor.PERMISSION_READ);

characteristic.addDescriptor(descriptor);

BluetoothGattService service = new BluetoothGattService(serviceUUID,     BluetoothGattService.SERVICE_TYPE_PRIMARY);
service.addCharacteristic(characteristic);

mGattServer.addService(service);

0 个答案:

没有答案