我想知道远程物理设备中的哪些事件会在监听设备中触发ACTION_ACL_CONNECTED
和ACTION_ACL_DISCONNECTED
。我的测试结果毫无意义。我已经在几个分米内收集了几个设备:
首先,我手动配对Tab中的所有设备。除了Tab之外,PC和手机都没有与任何其他设备配对。 (标签永远不会以任何方式找到其中一个耳机,但可以通过手动和编程方式轻松找到它。然后我有一个简单的应用程序来启动发现,并监听和显示ACL广播。这就是所发生的事情(每次都是一样的,它的疯狂是一致的):
startDiscovery()
启用了所有设备: - PC是唯一找到的设备ACTION_ACL_CONNECTED
ACTION_ACL_DISCONNECTED
和ACTION_ACL_CONNECTED
快速连续选项卡ACTION_ACL_CONNECTED
startDiscovery()
: - PC是唯一找到的设备
手机,虽然手机只与Tab配对,不配
PC。否则,手机只对选项卡的耳机作出反应
永远不会做出反应。从这个混乱中得到什么?即使配对并且在范围内上电,也不能依赖导致ACTION_ACL_CONNECT
的设备吗?
以下是BroadcastReceiver和onCreate活动的方法,但我不认为此代码中的细节很重要:
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();
}
答案 0 :(得分:16)
我正在和机器人一起搞砸了很长一段时间了,
我可以告诉你:
只要成功建立连接,就会发送现在是相当讨厌的部分。
只要在硬件级别关闭连接,就会发送ACTION_ACL_DISCONNECTED。当发生这种情况时,设备本身就会有所改变。 如果您手动断开/插入其他设备,它会以某种方式向机器人发送“dude,im gone”信号,而在一段时间后,一些看门狗咆哮并且连接正在关闭且意图被发送。 / p>
现在我只尝试使用我连接的SPP设备。 耳机afaik自己主动连接,因为它不是SPP。因此,如果您已配对并处于聆听模式,它会自动连接到您。现在我不知道如果你“断电”耳机会做什么。也许它正确断开连接或者它可能只是在不说再见的情况下破坏连接。在后一种情况下,监视器需要一段时间才能从机器人侧断开,这可能需要0到20秒,不要问我为什么,这只是我的观察。