英文:
Android: BluetoothAdapter getBluetoothLeAdvertiser() is null
问题
我正在尝试通过蓝牙实现设备间的通信,但遇到了问题。我正在使用以下代码获取 BluetoothManager
和 BluetoothAdapter
:
manager = (BluetoothManager)context.getSystemService(Context.BLUETOOTH_SERVICE);
adapter = manager.getAdapter();
在获取适配器之后,我尝试获取设备二的 BluetoothLeAdvertiser
,以便能够找到并连接到设备一。然而,我遇到了一个奇怪的情况。
adapter.isMultipleAdvertisementSupported()
返回 false
,而 adapter.getBluetoothLeAdvertiser()
返回 null
,这是预期的,除了以下情况:
adapter.getBluetoothLeScanner()
不会返回 null,当我通过 ADB 执行 pm list features
时,会列出 feature:android.hardware.bluetooth
和 feature:android.hardware.bluetooth_le
,因此我会认为 getBluetoothLeAdvertiser()
不会返回 null
。我在这方面的假设是错误的吗?
我今天进行了相当多的研究,但在这个特殊情况下找不到太多信息。
英文:
I'm attempting to have device to device communication via Bluetooth but I'm running into an issue. I'm getting the BluetoothManager
and BluetoothAdapter
using the below code:
manager = (BluetoothManager)context.getSystemService(Context.BLUETOOTH_SERVICE);
adapter = manager.getAdapter();
After getting the adapter, I'm then trying to get the BluetoothLeAdvertiser
for device two to be able to find and connect to device one. However, I'm running into a weird case.
adapter.isMultipleAdvertisementSupported()
is returning false
and adapter.getBluetoothLeAdvertiser()
is returning null
which is expected except for the following:
adapter.getBluetoothLeScanner()
does not return null and when I execute pm list features
via ADB feature:android.hardware.bluetooth
and feature:android.hardware.bluetooth_le
are both listed so I would assume that getBluetoothLeAdvertiser()
wouldn't return null
. Am I wrong in assuming that?
I've been researching this quite a bit today and can't find a whole lot about this unique case.
答案1
得分: 0
最可能的解释是您的安卓设备不支持蓝牙广播。绝大多数较新的设备支持此功能,但并非普遍适用。许多旧款安卓设备不支持广播。
请查看此处链接,以获取已知不支持广播的设备列表。
英文:
The most likely explanation is that your Android device does not support bluetooth advertising. The vast majority of newer devices do support this, but it is not universal. Many older Android devices do not support advertising.
See here for a list of devices that are known not to support advertising.
专注分享java语言的经验与见解,让所有开发者获益!
评论