This article from http://blog.csdn.net/hellogv/, reference must indicate the source!
Last time I talked about communication between Android phones and BLE terminals, and the most common BLE terminal should be the iBeacon base station proposed by Apple. IBeacon is based on BLE. It is characterized by sending messages externally through broadcasting. Mobile phones do not need to connect to the iBeacon base station to obtain its information. Currently, iBeacon is mainly used for indoor positioning and marketing information push, it carries specific information in the broadcast sent by BLE to be identified as iBeacon. When using iBeacon in iOS, you must register iBeacon UUID and the corresponding text description through passbook. on Android, there is no background Bluetooth search service similar to passbook, developers must handle such services by themselves. This time we will talk about searching for base stations and displaying iBeacon base station parameters on Android phones.
It is not difficult to search for an iBeacon base station. The core is the kernel thadapter. LeScanCallback ()OnLeScan(Final effecthdevice device, int Arg, byte [] scanRecord), and the information for identifying iBeacon lies in the scanRecord array. Follow:
// AirLocate:
// 02 01 1a 1a ff 4c 0002 15# Apple's fixed iBeacon advertising prefix
// E2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 # iBeacon profile uuid
// 00 00 # major
// 00 00 # minor
// C5 # The 2's complement of the calibrated Tx Power
At the same time, note that the UUID of iBeacon is irrelevant to the UUID of BLE Service, Characteristic and Descriptor. The UUID of iBeacon is issued during broadcast and is a standard defined by Apple, the Service, Characteristic, and Descriptor must be connected to the BLE terminal, which is the BLE standard.
The running result of the Code in this article is as follows. The ever-changing body of bsns can be used for distance determination. However, the txPower of this module is not accurate, so ranging is meaningless:
Download: Workshop.