Detect a nearby beacon even if the Bluetooth is switched off

Viewed 74

I am developing an app which detects for nearby beacons for the users to record a certain movement. I am using the AltBeacon library to do so. It works perfectly when I have the Bluetooth on.

public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region)
            {

                Logr.d(TAG, "didRangeBeaconsInRegion size:" + beacons.size());
                
                for (Beacon b : beacons)
                    {
                        try
                        {
                            String json = (new Gson()).toJson(beaconIdList);
                            Logr.d(TAG, json, "");

                            if (b.getId1() == null)
                            {
                                continue;
                            }
                            if (b.getId2() == null)
                            {
                                continue;
                            }
                            if (b.getId3() == null)
                            {
                                continue;
                            }

                            String id1 = b.getId1().toString();
                            String id2 = b.getId2().toString();
                            String id3 = b.getId3().toString();

                            String finalId = id1 + ":" + id2 + ":" + id3;
                            Integer index = beaconIdList.indexOf(finalId);

                            if (index >= 0)
                            { 
                                // index = -1 means that no match
                                Logr.d(TAG, "beacon matched: " + finalId, "");

                            }
                            else
                            {
                                Logr.d(TAG, "beacon unmatched: " + finalId + ":" + b.getDistance(), "");
                            }
                        }
                        catch(Exception ex)
                        {
                        
                        }
                    }
                }
            }

In some cases it may happen that the user turns of the Bluetooth. In such cases I still want to record the movement. With reference to this SO answer, it can be done on iOS using with the help of location services.

Is the same possible for Android?

Any suggestions will be a great help.

1 Answers

This question should be really simple to answer. If a Bluetooth radio is powered off, it simply cannot detect external Bluetooth radio signals, including beacons. This rule is governed by the laws of physics.

What makes the answer more complicated is that both Android and iOS play games with what the "Bluetooth off" settings really mean. Off does not really mean off. To make things more complicated, the way this behaves varies by operating system version and platform.

In general, newer versions of both iOS and Android have two different Bluetooth settings: (1) quick panel settings you get by swiping down from the top of the screen and (2) the full setting you get by going to the Settings app and drilling down into Bluetooth.

iOS 11+

                   Beacon Detection    
Setting            iBeacon  Others*    Bluetooth Connections
-----------------  ------  --------    --------------------- 
Bluetooth On        YES       YES              YES
Quick Setting Off   YES       NO               NO
Full Setting Off    NO        NO               NO

Note: * Other beacon types include AltBeacon, Eddystone, etc.

Pixel/Samsung Devices w/ Android 9+

Setting            Beacon Detection    Bluetooth Connections
-----------------  ----------------    --------------------- 
Bluetooth On            YES                    YES
Quick Setting Off*      YES                    NO
Full Setting Off        NO                     NO

Note: * Android version 9+ also has a further setting under Location -> WiFi and Bluetooth Scanning: "Allow apps and services to scan for nearby devices at any time, even when Bluetooth is off. This can be used for example to improve location-based features and services." This is enabled by default, but if switched off, it makes the Quick Setting behave like the Full Setting.

The table above applies to Samsung and Pixel devices. Unfortunately, the fragmented world of Android means that any OEM is able to customize this behavior. Don't be surprised if you find that a bargain Android phone or older OS version behaves differently.

Finally it should be noted that on both Android and iOS beacon detection requires that:

  • Location is turned on in settings
  • Location permissions have been granted to the app by the user
Related