don / cordova-plugin-ble-peripheral

Apache Cordova plugin for implementing BLE (Bluetooth Low Energy) peripherals.
Other
31 stars 31 forks source link

onStartFailure: ERROR code 1 (device name too long) #22

Closed ragcsalo closed 8 months ago

ragcsalo commented 8 months ago

Since I've added the BLUETOOTH_ADVERTISE permission, the plugin worked fine on Android 13.

Now I wanted to use it on Android 14, and the advertisement won't start (onStartFailure: error code 1). I can configure and create the service and characteristic, just can't start advertising...

Any of you faced the same issue?

ragcsalo commented 8 months ago

Found the solution :-)

First of all, ERROR code 1 means the advertisement data is longer than 31 bytes, which is usually caused by a too long device name. So the solution is to exclude the device name from the advertisement data, and put it in the scan response data.

1) In BLEPeripheralPlugin.java search for builder.setIncludeDeviceName(true); and set it to false.

2) Search for "action.equals(START_ADVERTISING)" and add a scan response like this:

AdvertiseData scanResponse = new AdvertiseData.Builder()
                    .setIncludeDeviceName(true)
                    .build();

            bluetoothLeAdvertiser.startAdvertising(advertiseSettings, advertisementData, scanResponse, advertiseCallback);

This way there will be no error code anymore. :-)

ragcsalo commented 8 months ago

Issue solved. :-)