Android4.3 has standardized the BLE API, but until now 4.4, some features are not perfect.
In the BLE protocol, there are two roles, the perimeter (periphery) and the Center (central), the periphery is the data provider, the central is the data use/processor; in the iOS SDK, you can use an iOS device as a perimeter or as a central; Inside the SDK, until now the newest android4.4.2,android mobile phone can only use and process data as the center; Where does the data come from? From BLE devices, many wearable devices now use BLE to provide data.
A central can be connected to multiple peripherals at the same time, but only one central area is connected at a time.
If you know the concept, take a look at the four key classes of the Android BLE SDK (Class):
A) Bluetoothgattserver as a peripheral to provide data; Bluetoothgattservercallback returns to the surrounding state.
b) Bluetoothgatt uses and processes data as a central part; Bluetoothgattcallback returns to the central State and data provided by the perimeter.
Bluetoothgatt
/*
* Use if (gatt==null) to determine if GATT has been created, if created, using Gatt.connect (); Re-establish the connection.
* But in this case the result of the test is that reconnecting takes a long time.
* The solution is through GATT = Device.connectgatt (this, false, Gattcallback); A new Connection object is established, which is obviously much faster than the previous method.
* However, the direct result of multiple creation of the GATT connection object is that more than 6 GATT has been created and will no longer be connected to any devices, since the number of simultaneous connections to ble in Android is limited to 6
* The workaround is to execute the gatt.close () once each time you reconnect, and close the previous connection.
* Some people say why not in Gatt.disconnect (); add a gatt.close (), because if Gatt.close () is executed immediately, the Gattcallback will not be able to receive state_disconnected status.
* Of course, the best way is to execute Gatt.close () after Gattcallback receives state_disconnected, which logically will be more clear.
*/
Readcharacteristic writecharacteristic
Android bluetooth® (Bluetooth) (two)