简体   繁体   中英

Android Bluetooth Low Energy Motorola API pairing

I am working on using the BT 4.0 API that Motorola has provided with the RAZR. In one of their documents it states to use the Android API to pair before connecting and using their framework. Per their instructions I have been pairing with OS Bluetooth settings application, but it never prompts me for a key. 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. They reference the "createBond()" function which, to my knowledge, is not an accessible function (at least not without some squirrely libraries or reflection).

Any advice is greatly appreciated, especially anyone who has used the API successfully, if they could give an account of their process. 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.

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:

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

I guess motorola stack has BLE support. 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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