How to connect Android device to an iOS device over BLE (Bluetooth Low Energy) How to connect Android device to an iOS device over BLE (Bluetooth Low Energy) ios ios

How to connect Android device to an iOS device over BLE (Bluetooth Low Energy)


Adding a summary for reference:

What could it be? There are some limitations on Android or iOS that don't permit to connect from an Android to an iOS or viceversa?

When connecting to a GATT server that is advertised as dualmode (BLE and BR/EDR) device by calling connectGatt(...), the TRANSPORT_AUTO flag that is internally added makes Android to default to the BR/EDR mode (link).

Following workarounds are possible:

  1. Peripheral side: Stop advertising BR/EDR capabilities by adjustingthe appropriate flags (link)
  2. Central side: Set the transport parameter explicitely toTRANSPORT_LE by calling the hidden version of connectGatt() usingreflection

Example:

public void connectToGatt(BluetoothDevice device) {       ...       Method m = device.getClass().getDeclaredMethod("connectGatt", Context.class, boolean.class, BluetoothGattCallback.class, int.class);       int transport = device.getClass().getDeclaredField("TRANSPORT_LE").getInt(null);     // LE = 2, BREDR = 1, AUTO = 0       BluetoothGatt mGatt = (BluetoothGatt) m.invoke(device, this, false, gattCallback, transport);       ... }

Edit 4/2016

As Arbel Israeli pointed out in the comment, Google introduced an overloaded version of connectGatt(...) which allows to specify the transport in Android M.


I've written a simple working example, well relatively simple, and included it open-source on Github: https://github.com/GitGarage. So far it has only been tested with an Android Nexus 9 and an iPhone 5s, but I presume it would also work with a Nexus 6 and various iPhone types. So far it is set up explicitly to communicate between one Android and one iPhone, but I presume it is tweakable to do much more.


Maybe a bit delayed, but perhaps your pain can be relieved slightly ;)

We have been experimenting a lot with cross platform BLE connections (iOS<-> Android) and learned that there are still many incompatibilities and connection issues. Aside to the instability of Android you should also consider that still, as of today, not that many Android devices actually support the BLE Peripheral mode.

Therefore, if your use case is feature driven and you only need basic data exchange I would suggest to look at Frameworks and Libraries that can achieve cross platform communication for you, without you needing to build it up from scratch.

For example: http://p2pkit.io or google nearby

Disclaimer: I work for Uepaa, developing p2pkit.io for Android and iOS.