本文介绍了什么触发 BluetoothDevice.ACTION_ACL 广播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道远程物理设备中的哪些事件会触发监听设备中的 ACTION_ACL_CONNECTEDACTION_ACL_DISCONNECTED.我的测试结果毫无意义.我已经收集了几台相距几分米的设备:

I would like to know what events in remote physical devices trigger ACTION_ACL_CONNECTED and ACTION_ACL_DISCONNECTED in a listening device. My test results make no sense. I have gathered several devices within a few decimeters of each other:

  • 运行 Android 3.1 的 Galaxy Tab P7500
  • 运行 Android 2.2 的 i5500 手机
  • 带有蓝牙 USB 加密狗的 WinXP 电脑
  • 两个带开/关按钮的耳机

首先,我通过选项卡手动与所有设备配对.PC 和手机均未与 Tab 以外的任何其他设备配对.(其中一个耳机永远无法通过选项卡以任何方式找到,但可以通过手动和编程方式轻松地从手机中找到).然后我有一个简单的应用程序来开始发现,它侦听和显示 ACL 广播.这就是发生的事情(每次都发生同样的事情,它的疯狂是一致的):

First, I pair manually with all devices from the Tab. Neither the PC nor the phone are paired with any other device but the Tab. (One of the headsets can never be found by the tab in any way, but it can easily be found from the phone both manually and programmatically). Then I have a simple app to start discovery and which listens to and displays the ACL broadcasts. And this is what happens (same thing every time, it's consistent in its madness):

  • startDiscovery() 从 Tab 启用所有设备: - PC 是唯一找到的设备
  • 在 PC 上禁用蓝牙: - 选项卡上没有反应
  • 在 PC 上启用蓝牙: - 选项卡上没有反应
  • startDiscovery() from Tab with all devices enabled: - The PC is the only device found
  • Disable bluetooth on PC: - No reaction on the Tab
  • Enable bluetooth on PC: - No reaction on the Tab
  • 第一次打开耳机: - ACTION_ACL_CONNECTED 在选项卡上
  • 关闭耳机: - 选项卡上没有反应
  • 再次打开耳机: - ACTION_ACL_DISCONNECTEDACTION_ACL_CONNECTED 在选项卡上快速连续
  • Power on headset 1st time: - ACTION_ACL_CONNECTED on the Tab
  • Power off headset: - No reaction on the Tab
  • Power on headset again: - ACTION_ACL_DISCONNECTED and ACTION_ACL_CONNECTED in quick succession on the Tab
  • 在 Tab 上禁用蓝牙:- 在 Tab 上没有反应
  • 在选项卡上启用蓝牙:- 选项卡上的耳机ACTION_ACL_CONNECTED
  • startDiscovery() 来自手机: - PC 是唯一被发现的设备手机,虽然手机只和Tab配对,没有配对个人电脑.否则,手机只会对 Tab从不反应.
  • startDiscovery() from phone: - The PC is the only device found by thephone, although the phone is only paired with the Tab, not with thePC. Otherwise, the phone only reacts to the headset which the Tabnever reacts on.

如何解决这个烂摊子?不能依赖导致 ACTION_ACL_CONNECT 的设备,即使它已配对并在范围内通电?

What to make out of this mess? Can't one rely on a device causing an ACTION_ACL_CONNECT even when it is paired and powers up within range?

以下是 BroadcastReceiver 的方法和 onCreate 的活动,但我不希望此代码中的细节很重要:

Here are the methods for BroadcastReceiver and the activities onCreate, but I don't expect details in this code to matter:

BroadcastReceiver intentReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        if (device != null) {
            name = device.getName();
        Log.v(TAG, "Device=" + device.getName());
        }
        else {
            name = "None";
        }

        if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
            text1.setText(name + " connected " + (checkCounter++));
            Log.v(TAG, "connected: " + device);
        }
        else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
            text2.setText(name + " disconnected " + (checkCounter++));
        Log.v(TAG, "disconnected: " + device);
        }
        else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            text3.setText( name + " found " + (checkCounter++));
        Log.v(TAG, "found: " + device + "");
        }
        else if (blueAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
            text4.setText("Started " + (checkCounter++));
            Log.v(TAG, "Discovery started");
        }
        else if (blueAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            text4.setText("Finished " + (checkCounter++));
            Log.v(TAG, "Discovery finished");
        }
    }
};


public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.bluetoothlayout);

    text1 = (TextView)findViewById(R.id.textView1);
    text2 = (TextView)findViewById(R.id.textView2);
    text3 = (TextView)findViewById(R.id.textView3);
    text4 = (TextView)findViewById(R.id.textView4);

    BluetoothDevice mw600 =         blueAdapter.getRemoteDevice("58:17:0C:EB:C5:08");
    BluetoothDevice bt500 =         blueAdapter.getRemoteDevice("00:1D:43:00:C4:54");
    BluetoothDevice galaxyTab = blueAdapter.getRemoteDevice("00:07:AB:6A:96:7D");
    BluetoothDevice pcDongle =  blueAdapter.getRemoteDevice("00:15:83:4D:8B:57");

    intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothDevice.ACTION_FOUND);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
    intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    intentFilter.addAction(blueAdapter.ACTION_DISCOVERY_STARTED);
    intentFilter.addAction(blueAdapter.ACTION_DISCOVERY_FINISHED);
    if (!isReceiverRegistered) {
        registerReceiver(intentReceiver, intentFilter);
        isReceiverRegistered = true;
    }
    if (!blueAdapter.isEnabled()) {
        blueAdapter.enable();
    }
    blueAdapter.startDiscovery();
}

推荐答案

我使用 androids 工作已经很长时间了,

I'm working with androids really messed up bt for quite some time now,

这里是我可以告诉你的:

here is what i can tell you:

ACTION_ACL_CONNECTED 每当成功建立连接时发送.这个很简单.

ACTION_ACL_CONNECTED is sent whenever a successful connection was established. This one is as simple as it gets.

现在是相当烦人的部分.

Now the rather annoying part.

只要在硬件级别关闭连接,就会发送 ACTION_ACL_DISCONNECTED.何时发生这种情况取决于设备本身.如果您手动断开/拔出其他设备,它不会向机器人发送老兄,我走了"信号,而是在长达 20 秒后,一些看门狗吠叫并且连接正在关闭并发送意图.

ACTION_ACL_DISCONNECTED is sent whenever the connection was closed on a HARDWARE level. WHEN that happens is a bit up to the device itself.IF you manually disconnect/plug out the other device, it somehow does not send a "dude, im gone" signal to the droid, instead after up to 20 seconds some watchdog barks and the connection is being closed and the intent is sent.

现在我只在我连接的 SPP 设备上尝试了这个.耳机 afaik 正在主动连接,因为它不是 SPP.因此,如果您已配对并处于聆听模式,它会自动连接到您.现在我不知道如果你关机"耳机会做什么.也许它正确断开连接,或者它只是中断了连接而没有说再见.在后一种情况下,看门狗从机器人端断开连接需要一些时间,可能需要 0 到 20 秒,别问我为什么,这只是我的观察.

Now i did try this only with SPP devices that I connect to.A headset afaik is actively connecting by itself because its not SPP. So it automatically connects to you, if you are paired and in listening mode. Now i dont know what the headset does if you "power it off". Maybe it disconnects properly or maybe it just disrupts the connection without saying goodbye. In the latter case it would take some time for the watchdog to disconnect from the droid side, which can take from 0 to 20 seconds, dont ask me why, its just my observation.

这篇关于什么触发 BluetoothDevice.ACTION_ACL 广播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 02:02