Android 4.3 BTLE as server: How to start advertisements?

后端 未结 4 536
悲哀的现实
悲哀的现实 2021-02-01 06:31

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 exampl

相关标签:
4条回答
  • 2021-02-01 06:56

    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.

    0 讨论(0)
  • 2021-02-01 06:56

    You will need API Level 21.

    import android.bluetooth.le;
    ...
    ...
    BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter myBluetoothAdapter = bluetoothManager.getAdapter();
    BluetoothLeAdvertiser myBluetoothLeAdvertiser =  myBluetoothAdapter.getBluetoothLeAdvertiser ();
    myBluetoothLeAdvertiser.startAdvertising (AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseCallback callback);
    

    Useful link is : https://developer.android.com/about/versions/android-5.0.html

    0 讨论(0)
  • 2021-02-01 07:04

    It seems the getProfileProxy does not respond to the GATT or GATT_SERVER request. The API suggests advertising support, but there is no code implemented behind yet. (Android Issue Tracker)

    Same half-way implemented APIs were released initially when NFC was introduced and Google iterated adding more well rounded functionality with follow-up releases.

    0 讨论(0)
  • 2021-02-01 07:15

    As I see it, BLE advertising ability (aka peripheral mode) will be added to Android with the upcoming version 4.4.3 of Kitkat. It's supposed to be released next week, but the changelog has already been leaked accidentially, see Google cache or here in line 2554: peripheral mode (3/4): Add peripheral mode API.

    I guess we will know more soon.

    0 讨论(0)
提交回复
热议问题