首页 文章

Android BLE ACTION_ACL_CONNECTED未调用配对设备

提问于
浏览
6

我使用的是Android 4.4 . 我有2个蓝牙设备,一个老式蓝牙和一个BLE . 就它们传输的数据而言,它们在功能上是相同的 . 它们都有一个按钮,可以在按下时连接和传输数据 .

我有蓝牙权限并在我的清单中注册了BroadcastReceiver,就像这样

...

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

...

<receiver
    android:name=".BluetoothBroadcastReceiver">
    <intent-filter>
        <action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
        <action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
        <action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
    </intent-filter>
</receiver>

为了测试,我只是在BroadcastReceiver中记录对onReceive的调用

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, intent.getAction());
}

问题在于:两个设备都与手机配对,但只有老式蓝牙设备在按下蓝牙设备时生成ACTION_ACL_CONNECTED / ACTION_ACL_DISCONNECTED广播 . 当BLE设备尝试连接和传输时,没有任何反应 .

如果我正在使用主动扫描BLE连接,我能够成功连接和接收来自BLE设备的数据

mBluetoothAdapter.startLeScan(mLeScanCallback);

我是否必须明确扫描BLE设备以允许它们连接? BLE设备是否在未明确扫描BLE设备时生成ACTION_ACL_CONNECTED / ACTION_ACL_DISCONNECTED广播?或者,如果与手机配对,它们是否应自动连接?

1 回答

  • 0

    ACTION_ACL_CONNECTED/ACTION_ACL_DISCONNECTED 广播仅适用于BR / EDR(经典蓝牙),不适用于BLE .

    对于BLE,您必须使用最新Android版本提供的API和回调 .

相关问题