gpt4 book ai didi

android - Android API 20 是否允许支持蓝牙 LE 的设备充当外围设备?

转载 作者:太空宇宙 更新时间:2023-11-03 12:53:51 26 4
gpt4 key购买 nike

我正在使用以下代码将 Android 设备设置为外围设备,但它似乎无法正常工作。您知道 API 20 是否支持外设模式吗?

BluetoothGattServer mGattServer;
public void startPeripheralGattServer() {
final BluetoothManager bluetoothManager =
(BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE);

mGattServer = bluetoothManager.openGattServer(getApplicationContext(), new BluetoothGattServerCallback() {

@Override
public void onCharacteristicReadRequest(BluetoothDevice device, int requestId,
int offset, BluetoothGattCharacteristic characteristic) {

if (mGattServer != null) {
mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, new byte[] { '1' });
}
}
});

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

最佳答案

基于此Google I/O video for Bluetooth Low Energy ,外设模式将从 Android API 20 (Android L) 及更高版本开始可用。

关于android - Android API 20 是否允许支持蓝牙 LE 的设备充当外围设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24520080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com