简体   繁体   English

Android蓝牙低能耗摩托罗拉API配对

[英]Android Bluetooth Low Energy Motorola API pairing

I am working on using the BT 4.0 API that Motorola has provided with the RAZR. 我正在使用Motorola随RAZR提供的BT 4.0 API。 In one of their documents it states to use the Android API to pair before connecting and using their framework. 他们的一份文件中,它声明在连接和使用他们的框架之前,先使用Android API进行配对。 Per their instructions I have been pairing with OS Bluetooth settings application, but it never prompts me for a key. 按照他们的指示,我一直在与OS蓝牙设置应用程序配对,但是它从未提示我输入密钥。 It will pair but doesn't appear to bond, and this is critical for me. 它会配对,但似乎没有结合,这对我来说至关重要。

My question is, when they say "using the Android API" is this referring to simply using the OS Bluetooth utility to pair before hand (like I have been doing), or is there some way to do it with code in my application. 我的问题是,当他们说“使用Android API”时,是指仅使用OS蓝牙实用程序事先进行配对(就像我一直在做的那样),或者有某种方法可以在我的应用程序中使用代码。 They reference the "createBond()" function which, to my knowledge, is not an accessible function (at least not without some squirrely libraries or reflection). 他们引用了“ createBond()”函数,据我所知,该函数不是可访问的函数(至少并非没有一些松散的库或反射)。

Any advice is greatly appreciated, especially anyone who has used the API successfully, if they could give an account of their process. 我们将不胜感激任何建议,尤其是那些成功使用了API的人,只要他们能够说明其过程。 I'm just looking for some clarity at this point :) 我现在只是想澄清一下:)

Lloyd, 劳埃德,

You are correct, follow the instructions in the link you posted. 您是正确的,请按照发布的链接中的说明进行操作。

Outside of coding, when they say use the standard android api for "non-le" operations, they mean go ahead and pair the ble device the same way you would any bluetooth classic devices inside android settings -> wireless & network -> bluetooth -> scan for devices. 在编码之外,当他们说使用标准的android API进行“非le”操作时,他们的意思是继续进行ble设备配对,就像在android设置中的任何蓝牙经典设备一样->无线和网络->蓝牙- >扫描设备。

If the device you are using is a motorola le compatible device the ble device will be paired but not connected. 如果您使用的设备是摩托罗拉兼容设备,则该设备将配对但未连接。

Now, in the code, you can detect this paired device through the same method of 现在,在代码中,您可以通过以下相同方法来检测此配对设备:

BluetoothAdapter.getDefaultAdapter().getBondedDevices()

To double check if your Android Phone is LE compatible, run this code: 要再次检查您的Android Phone是否兼容LE,请运行以下代码:

 public static boolean checkBLESupport() {
        boolean deviceSupportsLE;

    try {
        @SuppressWarnings({ "unused", "rawtypes" })
        Class object = Class.forName("android.server.BluetoothGattService");
        deviceSupportsLE = true; 
    } catch (Exception e) {
        deviceSupportsLE = false; 
    }

    return deviceSupportsLE;
}

And to double check if the bluetooth device you paired is LE, when you are looping through the bonded devices. 并再次检查在配对设备之间循环时,您配对的蓝牙设备是否为LE。 Check the device with this code. 使用此代码检查设备。

 if (device.getBluetoothClass() == null) {
    Log.i(TAG, "This device is BLE compatible");
        b = true;
} else {
    Log.i(TAG, "This device is not BLE");
        b = false;
}

Now for establishing connection from your LE compatible phone to your LE compatible bluetooth device, follow the Gatt service instructions under the link you posted. 现在,要建立从LE兼容电话到LE兼容蓝牙设备的连接,请遵循发布的链接下的Gatt服务说明。 http://developer.motorola.com/docs/bluetooth-low-energy-api/ http://developer.motorola.com/docs/bluetooth-low-energy-api/

Take note that under this example it is connecting to a bluetooth low energy heart rate monitor. 请注意,在此示例下,它正在连接蓝牙低能耗心率监测器。

If you are not trying to connect to the heart rate monitor with LE heart rate profile, here is a link to another Motorola document that details creating your own LE Profile to use with the GATT framework. 如果您不尝试使用LE心率配置文件连接到心率监测器,则这里是另一个Motorola文档的链接,该文档详细介绍了如何创建自己的LE Profile以与GATT框架一起使用。 http://developer.motorola.com/docs/bluetooth-low-energy-gatt-framework-api/ http://developer.motorola.com/docs/bluetooth-low-energy-gatt-framework-api/

If the instructions are not clear enough at any point in either of these documents, motorola offers sample android applications using the frameworks in those documents. 如果以上两个文档中的任何一点都不够清晰,则说明Motorola使用这些文档中的框架提供了示例android应用程序。

I guess motorola stack has BLE support. 我猜摩托罗拉堆栈具有BLE支持。 But what i feel is that it does not pair with the devices that require bonding though It does work some sensors. 但是我的感觉是,尽管它确实可以在某些传感器上工作,但它并不与需要绑定的设备配对。 I have tried with a proximity sensor that require bonding. 我尝试了需要粘合的接近传感器。 It never gets paired though the devices is discovered with Razr which even does not with S3. 尽管设备是通过Razr发现的,但是甚至没有使用S3,但它从未配对。

There's a helpful video here . 有一个有用的视频在这里

Late to the game, but can confirm - 比赛迟到了,但可以确认-

If your BLE Peripheral requires bonding, Moto X - and some other older Motorola devices - MUST be paired via Bluetooth Settings prior to programmatic connection via the Android GATT interface. 如果您的BLE外围设备需要绑定,则必须先通过蓝牙设置将Moto X和其他一些较旧的摩托罗拉设备配对,然后再通过Android GATT接口进行编程连接。

If you bond via the createBond method, or reading of an encrypted characteristic, your connection will be dropped typically in under 60 seconds, despite DDMS logs that show a good bond may be established. 如果您通过createBond方法进行绑定,或者读取了加密的特征,则尽管可能会建立表明绑定良好的DDMS日志,但通常会在60秒内断开连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM