是什么触发了BluetoothDevice.ACTION_ACL广播? [英] What triggers the BluetoothDevice.ACTION_ACL broadcasts?

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

问题描述

我想知道事件的远程物理设备触发ACTION_ACL_CONNECTED和ACTION_ACL_DISCONNECTED听音装置中。我的测试结果是没有意义的。

:我已在彼此的几个分米聚集几个设备

运行的Galaxy Tab P7500的Andr​​oid 3.1

一个I5500手机运行的是Android 2.2

一台PC的winXP与蓝牙USB适配器

两款耳机开/关按钮

首先,我手动配对来自标签的所有设备。无论是PC还是手机配对与任何其他设备,但该选项卡。 (其中一个耳机不能以任何方式的标签中,但它很容易被发现从手机手动和编程)。然后,我有一个简单的应用程序开始发现和监听并显示ACL广播。这是发生了什么(同样的事情每一次,它在它的疯狂一致):

  • startDiscovery()的标签和所有设备上启用: - 将PC上的唯一设备发现
  • 在PC禁用蓝牙: - 在标签
  • 无反应
  • 在PC上开启蓝牙: - 在选项卡中没有反应

  • 开机耳机1日时间: - ACTION_ACL_CONNECTED上的Tab

  • 在电源关闭耳机: - 在选项卡中没有反应
  • 开机耳机再次: - ACTION_ACL_DISCONNECTED和 ACTION_ACL_CONNECTED快速连续的标签

  • 在选项卡禁用蓝牙: - 在选项卡中没有反应

  • 启用蓝牙的标签: - 耳机ACTION_ACL_CONNECTED上的Tab

  • 从电话
  • startDiscovery(): - PC是由发现的唯一设备 手机,虽然手机只搭配的标签,不与 PC。否则,手机只反应了耳机,该耳机的标签 从来没有反作用于。

怎么做出来这个烂摊子?不能在一个依靠在设备上引起ACTION_ACL_CONNECT即使配对并接通电源范围内?

下面是方法的BroadcastReceiver和活动的onCreate,但我不希望在这个code细节无关紧要:

 的BroadcastReceiver intentReceiver =新的BroadcastReceiver(){
    公共无效的onReceive(上下文的背景下,意图意图){
        串动= intent.getAction();
        BluetoothDevice类设备= intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        如果(设备!= NULL){
            名称= device.getName();
        Log.v(TAG,设备=+ device.getName());
        }
        其他 {
            NAME =无;
        }

        如果(BluetoothDevice.ACTION_ACL_CONNECTED.equals(动作)){
            text1.setText(姓名+连接+(checkCounter ++));
            Log.v(TAG,连接:+设备);
        }
        否则如果(BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(动作)){
            text2.setText(姓名+断开连接+(checkCounter ++));
        Log.v(TAG,断开+设备);
        }
        否则如果(BluetoothDevice.ACTION_FOUND.equals(动作)){
            text3.setText(姓名+发现+(checkCounter ++));
        Log.v(TAG,发现:+设备+);
        }
        否则如果(blueAdapter.ACTION_DISCOVERY_STARTED.equals(动作)){
            text4.setText(已启动+(checkCounter ++));
            Log.v(TAG,发现开始);
        }
        否则如果(blueAdapter.ACTION_DISCOVERY_FINISHED.equals(动作)){
            text4.setText(成品+(checkCounter ++));
            Log.v(TAG,发现拍完);
        }
    }
};


公共无效的onCreate(包savedInstanceState){

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

    文本1 =(TextView中)findViewById(R.id.textView1);
    文本2 =(TextView中)findViewById(R.id.textView2);
    文本3 =(TextView中)findViewById(R.id.textView3);
    文本4 =(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的=新的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);
    如果(!isReceiverRegistered){
        registerReceiver(intentReceiver,IntentFilter的);
        isReceiverRegistered = TRUE;
    }
    如果(!blueAdapter.isEnabled()){
        blueAdapter.enable();
    }
    blueAdapter.startDiscovery();
}
 

解决方案

我正与机器人真的搞砸BT相当长的一段时间了,

这里是我可以告诉你:

只要成功建立连接ACTION_ACL_CONNECTED发送。这其中很简单,因为它得到。

现在的相当恼人的部分。

每当连接是在硬件层面封闭ACTION_ACL_DISCONNECTED发送。当发生这种情况是一个位到设备本身。 如果您手动断开/拔出其他设备,它并不会自动发送一个纨绔子弟,即时通讯已经信号给机器人,而是经过长达20秒的一些看门狗树皮和连接正在关闭,并意图发送。

现在我没有尝试这个只与我连接到SPP设备。 头戴式耳机AFAIK正在积极通过自身连接,因为它不是最高人民检察院。因此,它会自动连接到你,如果你是成对的,并在监听模式。现在,我不知道什么耳机呢,如果你关闭其电源。也许它断开正确或者它只是破坏了不辞而别的连接。在后一种情况下,将需要一段时间的监视,从机器人的一面,它可以从0到20秒断开,不要问我为什么,它只是我的观察。

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 decimeter of each other:

a Galaxy Tab P7500 running Android 3.1

a i5500 phone running Android 2.2

a PC winXP with a bluetooth USB dongle

two headsets with on/off buttons

First, I pair manually with all devices from the Tab. Neither PC nor 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, its consistent in its madness):

  • 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

  • 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

  • Disable bluetooth on Tab: - No reaction on the Tab

  • Enable bluetooth on Tab: - Headset ACTION_ACL_CONNECTED on the Tab

  • startDiscovery() from phone: - The PC is the only device found by the phone, although the phone is only paired with the Tab, not with the PC. Otherwise, the phone only reacts to the headset which the Tab never reacts on.

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?

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();
}

解决方案

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

here is what i can tell you:

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 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.

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广播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆