What does error code 2 in beacon_broadcast flutter package mean?

佐手、 提交于 2021-01-29 18:42:09

问题


I am making a beacon broadcast app using Flutter. The library I am using is "beacon_broadcast" at pub.dev. When I try to start it, the console says:

D/BeaconParser( 7318): Parsing beacon layout: m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25
D/BluetoothAdapter( 7318): isLeEnabled(): ON
D/BluetoothAdapter( 7318): isLeEnabled(): ON
E/BeaconTransmitter( 7318): Advertisement start failed, code: 2

What does error code 2 mean? I don't need any other help, I just want the meaning, so I think I don't need to show the code.

Also, if possible, please add a list of error codes and meanings.


回答1:


Every phone model has a different Bluetooth chip, each of which supports a limited number of "advertising slots". Each slot allows a single Bluetooth LE advertisement to be started. If the phone has already used all its available advertising slots, you get this error.

ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
Added in API level 21
public static final int ADVERTISE_FAILED_TOO_MANY_ADVERTISERS
Failed to start advertising because no advertising instance is available.

Constant Value: 2 (0x00000002)

See: https://developer.android.com/reference/android/bluetooth/le/AdvertiseCallback which has a list of all the other error codes, too.

Since the slots are a shared resource on the phone, it is possible that another app may be using some of the slots. Older phones like the Nexus 4 only supported one slot. Newer phones like the Pixel 3a support 10 or more slots. Some phones don't have any slots at all. See here for a list of devices with no advertising support.

Each phone OEM implements part of the bluetooth stack that bridges the hardware to the Android operating system. This code is almost always closed-source. Depending on how this OEM layer is implemented (and how correctly) it can affect how many advertising slots are available.

Unfortunately there are no APIs to query the total number of advertising slots that are in theory available on a phone. Without the source code from the OEM, the only way to tell is to do a factory reset on your phone (to be sure no other apps installed are using a slot), and build an app that tries to start one advertiser after another, counting up until one fails.



来源:https://stackoverflow.com/questions/61200485/what-does-error-code-2-in-beacon-broadcast-flutter-package-mean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!