turgos
turgos

Reputation: 1614

Does Android API 20 allows devices that support Bluetooth LE to act as a peripheral device?

I am using the below code to set the Android device act as peripheral, but it does not seem like working. Do you know if peripheral mode is supported with 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);
    }

Upvotes: 3

Views: 878

Answers (3)

Dat Nguyen
Dat Nguyen

Reputation: 1891

The peripheral mode is supported with API 20. However, to transmit as a peripheral mode, Android 5.0+ and firmware supporting Bluetooth Low Energy Peripheral Mode are required. As of December 2014, only Nexus 6 and Nexus 9 devices are known to have firmware that supports Bluetooth Low Energy Peripheral Mode.

Please click here get more information

Upvotes: 2

ARK
ARK

Reputation: 4074

They will be available from API Level 21

BLE Peripheral APIs avaliable from API Level 21

Upvotes: 0

KikiTheMonk
KikiTheMonk

Reputation: 1015

Based on this Google I/O video for Bluetooth Low Energy, peripheral mode will become available from Android API 20 (Android L) and above.

Upvotes: 3

Related Questions