BLE Advertisement in Android

后端 未结 3 419
南方客
南方客 2021-01-01 01:04

I am developing and app to Send BLE Advertisement packet in android. I have use AdvertiseData and AdverstiseSettings classes to generate the advertise packet. But when i do

相关标签:
3条回答
  • 2021-01-01 01:33

    See this question for a possible answer, BLE Advertisments are not supported on every device.

    Also try to omit the device name as suggested here.

    0 讨论(0)
  • 2021-01-01 01:44

    From my experience there are 4 types of Android devices in regard BLE advertisement:

    1. Devices with Android pre-5.0 - LE Advertisement not supported
    2. Devices with Android 5+ that don't support LE Advertisement and return null from getBluetoothLeAdvertiser(). Those devices return false from isMultipleAdvertisementSupported(). They do this even with Bluetooth ON (see Note below).
    3. Devices with Android 5+ that return the BluetoothLeAdvertiser object, but each try of advertising ends with ADVERTISE_FAILED_TOO_MANY_ADVERTISERS error (this is the case you have). Those devices return true from isMultipleAdvertisementSupported() which as you see is not true. So far I've seen only one phone from this category: Sony xperia z1 compact, but if there is one, there are more.
    4. Devices with Android 5+ that support LE Advertisement. Those return true from isMultipleAdvertisementSupported() but ONLY when Bluetooth is ON.

    Note: in the 2., 3. and 4. the BluetoothLeAdvertiser object is returned ONLY when Bluetooth is ON. Otherwise null is returned, so you actually have no clue whether the device supports LE Advertisement or not until Bluetooth is enabled.

    Check the nRF Connect app: Disable Bluetooth, install the app, open and select Advertiser tab or Navigation menu -> Device information. It will ask you to turn Bluetooth ON before the status will be shown.

    0 讨论(0)
  • 2021-01-01 01:55

    You only need to add this code: @TargetApi(Build.VERSION_CODES.M) over your method

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