Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 4.3 BTLE as server: How to start advertisements?

I am trying to implement a BTLE SERVER on the Nexus 7 with the new BTLE API in 4.3. I am running into several problems. First there are no examples with the SDK. The only example is for a client. Second, the documentation actually tells you to do the wrong thing. It states that one must use the BluetoothAdapter.getProfileProxy() with a BluetoothProfile.GATT_SERVER parameter to obtain the BluetoothGattServer object. This approach will work, but one will be unable to link one's implementation of the BluetoothGattServerCallback to the BLE stack. (This callback is how one responds to client read and write requests among other things.) However, after stumbling on issue 58582 a developer pointed to the new BluetoothManager.openGattServer() method which takes your callback as a parameter and returns a BluetoothGattServer object. Well, one problem solved.

The next issue is more problematic. The BluetoothGattServer documentation states that one can use this class to create and advertise Bluetooth LE services and characteristics. Creating the services, etc. was not problem but they neglect to say how to start advertising. There is no method in the class itself or any other of the classes that I can find.

Does anyone know how to do this? At the moment all I can see is to use the same approach as used by the client, but that approach involves scanning (which is not advertising). All the documentation further suggests that the BluetoothAdapter.startLeScan() IS indeed JUST for scanning.

So how do I invoke advertisements once all my services, characteristics, and descriptors are in place?

like image 908
Brian Reinhold Avatar asked Aug 08 '13 14:08

Brian Reinhold


People also ask

How do I enable BLE on android?

Use of the Bluetooth LE APIs requires you to declare several permissions in your manifest file. Once your app has permission to use Bluetooth, your app needs to access the BluetoothAdapter and determine if Bluetooth is available on the device. If Bluetooth is available, the device will scan for nearby BLE devices.

What are BLE settings?

In contrast to Classic Bluetooth, Bluetooth Low Energy (BLE) is designed to provide significantly lower power consumption. This allows Android apps to communicate with BLE devices that have low power requirements, such as proximity sensors, heart rate monitors, fitness devices, and so on.


1 Answers

As I understand, the Android implementation can only act as a central device, and not as a peripheral device. In Bluetooth Low Energy, only the peripheral can advertise. The central device can scan for advertisements from peripherals, and send connect requests as replies to (some kinds of) advertisements, to create a connection to the peripheral.

In BLE, there is a distinction between the concepts Central/Peripheral and Server/Client:

  • Central/Peripheral is relating to the network architecture, where the central is the hub in a star, with one or more peripherals connected to it. It will typically be a phone, tablet or computer. A peripheral device can only connect to one central at a time.

  • Server/Client (GATT server/client) is a higher level concept, related to the data that are kept in the devices and possibly communicated over the connection. Both central and peripheral devices can implement a GATT server and a GATT client, but is not required to have both.

So to answer your question: You cannot invoke advertisements. You will have to start scanning for peripheral devices to be able to make a connection to one or more of them.

Hope this helps.

like image 146
oyhovd Avatar answered Sep 19 '22 16:09

oyhovd