w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to provide custom UUID for Beacon scanning in Android?

Do not confuse a Bluetooth Service UUID with an iBeacon Proximity UUID. They may look alike, but have completely different values and purposes.

The startLeScan method you mention takes an optional service UUID to filter the scan for Bluetooth devices offering a particular service. This will not work to scan for iBeacons, which do not advertise specific services, and need extra software to decode their fields.

To scan for iBeacons with a particular Proximity UUID and decode their values, try the open source Android iBeacon Library which is designed to do exactly what you describe. Setting up a filter for a single Proximity UUID is as simple as:

Region("myRegion", "2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6", null, null));

A full example can be seen here.

If you want to roll your own, then you need to decode every bluetooth advertisement returned to the BluetoothAdapter.LeScanCallback, discard non-iBeacon advertisements, then compare the Proximity UUID of each iBeacon advertisement against the one you are looking for, and ignore any that do not match. The open source library mentioned above has a fromScanData method that decodes an advertisement into iBeacon fields here.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.