如何android系统autoconnects到配对的设备? [英] How android system autoconnects to paired device?

查看:668
本文介绍了如何android系统autoconnects到配对的设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是什么:

我不知道如何在Android系统(如Android智能手机),将​​自动连接到之前配对的设备。

I'm wondering how the android system (like Android smart phone) auto-connects to devices which is paired before.

例如的,我配对我的蓝牙耳机与我的Andr​​oid智能手机在的程序打开扫描/广告 - >点击配对第1天当我打开我的耳机广告,其第2天,3,4自动连接,等等。问题的关键是,我没有让我的智能​​手机扫描再次找到我(配对)耳机。

For example, I pair my bluetooth headset with my android smartphone in the procedure of "turn on scanning/advertising -> click pairing" on day 1. And when I turn on advertising on my headset, it connects automatically on day 2, 3, 4, and so on. The point is, I don't have to make my smartphone scan again to find my (paired) headset.

我不明白系统如何Android的认定配对的设备已打开。难道Android系统定期扫描在后台?即使我不点击扫描按钮?

I can't understand how android system finds that the paired device is turned on. Does the android system scan periodically in background? Even if I don't click "scan" button?

为什么我问:

我想让我的应用程序自动连接到定制BLE装置,使配对后。我成功了,使与配对(绑定)createBond()方法,但在那之后,我无法找到如何使自动连接。我知道我可以打开自动连接功能,这样的方式, connectGatt(XXX,真实,XXX),但当BLE装置断开几该自动连接功能不起作用天。

I want to make my app autoconnect to customized BLE device, after make pairing. I succeed to make pairing(bonding) with createBond() method, but after that, I couldn't find how to make autoconnect. I know I can turn on autoconnect function like this way, connectGatt(XXX, true, XXX), but this autoconnect function doesn't work when the BLE device is disconnected a few days.

所以,我要让我的应用程序的工作原理是android系统和蓝牙耳机。但我找不到蓝牙系统是如何运作的Andr​​oid甚至我掏AOSP codeS。

So I want to make my app works like android system and Bluetooth headset. But I couldn't find how android bluetooth system works even I dig AOSP codes.

我发现很多问题(<一个href=\"http://stackoverflow.com/questions/30460012/how-to-autoconnect-to-a-paired-device-ble-without-scanning\">here和)关于像我这样的问题,href=\"http://stackoverflow.com/questions/29717752/autoconnecting-to-known-ble-device\">但没有答案。

I found many questions (here and here) about problems like mine but there were no answers.

先谢谢了。

更新:

我发现 bt_btif 被激活(与LG的智能手机和Nexus 5)当配对耳机开启(开始投放广告)。但 bt_btif 不会与我的自定义BLE装置激活......我该怎么办?

I found that bt_btif gets activated (with LG smartphone and Nexus 5) when the paired headset is turned on (start advertising). But bt_btif doesn't get activated with my custom BLE device... What can I do?

推荐答案

我想我找到了解决办法。

I think I found a solution.

首先,我的问题解决方案:Android智能手机似乎发现从硬件两侧附近的蓝牙设备的状态变化。当配对的蓝牙耳机开始做广告,在HAL回调(我认为)被调用。

First, the solution for my question: Android smartphone seems to detect state changes of nearby bluetooth devices from the hardware sides. When the paired bluetooth headset starts to advertise, a callback in HAL (I think) is called.

所以我做了我的应用程序 connectGatt autoConnection = TRUE 来我想要的设备,使用MAC地址,当活动开始时(在 onResume() MainActivity )。

So I made my app to connectGatt with autoConnection=True to the device that I want, by using MAC address, when the activity is started (in onResume() of MainActivity).

如果我BLE外设不是广告的连接将失败。但是,当它启动时的广告,因为 autoConnection 参数设置为true的设备将自动连接。

The connection would fail if my BLE peripheral device is not advertising. But the device auto-connects when it starts advertising, because the autoConnection parameter was set to true.

这篇关于如何android系统autoconnects到配对的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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