Android bluetooth® (Bluetooth) (two)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.