3

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);
    }
turgos
  • 1,464
  • 1
  • 17
  • 28
  • Check out this related question: http://stackoverflow.com/questions/19717902/does-android-kitkat-allows-devices-that-support-bluetooth-le-to-act-as-a-periphe?rq=1 – Josh Jul 01 '14 at 23:05

3 Answers3

3

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

KikiTheMonk
  • 985
  • 10
  • 24
2

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

Dat Nguyen
  • 1,881
  • 17
  • 36
0

They will be available from API Level 21

BLE Peripheral APIs avaliable from API Level 21

ARK
  • 3,734
  • 3
  • 26
  • 29