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

Android API 20是否允许支持蓝牙LE的设备充当外围设备?,第1张

概述我使用以下代码将Android设备设置为外围设备,但它似乎不起作用.您知道API20是否支持外设模式?BluetoothGattServermGattServer;publicvoidstartPeripheralGattServer(){finalBluetoothManagerbluetoothManager=(BluetoothManager)this.getSys

我使用以下代码将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 API 20是否允许支持蓝牙LE的设备充当外围设备?全部内容,希望文章能够帮你解决Android API 20是否允许支持蓝牙LE的设备充当外围设备?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1107399.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存