How to scan BLE devices in Android without giving location permission? - android

Description:
I am scanning the nearby BLE devices in my android application and allowing users for these permissions ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION which requires enabling location in the Android device.
What I am looking for:
I need to remove the location permission from the app to scan nearby devices.

On Android 12 and higher, you should be able to use BLUETOOTH_SCAN as the permission.
On older devices, you have no choice but to request ACCESS_FINE_LOCATION. You do not need ACCESS_COARSE_LOCATION.

I believe it is not possible to do what you are trying to achieve. for more information check the android developer documentation.
https://developer.android.com/guide/topics/connectivity/bluetooth/ble-overview

Related

Does BLE connection require ACCESS_BACKGROUND_LOCATION permission in android 10?

I have job scheduler which searches BLE devices and connects in background. Android 10 introduced new ACCESS_BACKGROUND_LOCATION permission. Does ACCESS_BACKGROUND_LOCATION permission require to connection BLE device in background?
https://developer.android.com/guide/topics/connectivity/bluetooth#Permissions only mentions the app needs ACCESS_FINE_LOCATION, so I suspect you don't need ACCESS_BACKGROUND_LOCATION. But I see it likely this will be changed in the near future.
A quick look at https://android.googlesource.com/platform/packages/apps/Bluetooth/+/refs/tags/android-10.0.0_r32/src/com/android/bluetooth/gatt/GattService.java#1949 shows that only the fine permission seems to be needed, but I can have missed something.
I suggest you to simply try with only ACCESS_FINE_LOCATION to see what happens in the background.
I Think this article would help as it talks about location permission in android 11 and use of BLE.
Location.
also i would recommend you use Foreground services to give your user more insight on what your app is doing and allow them to determine if they need to give you app the permission once, or always.
Running a service in the foreground
Android documentation says:
If your app supports a service and can run on Android 10 (API level 29) or Android 11, you must also declare the ACCESS_BACKGROUND_LOCATION permission to discover Bluetooth devices. For more information on this requirement, see Access location in the background.
More information here: Android bluetooth permissions
So answer is: If you scan for devices or connect to them from service (even foreground service) you need to request for ACCESS_BACKGROUND_LOCATION permission.

Altbeacon can't find beacons on Samsung S8 when location is turned off since 2.16.2

I am building an Android app that scans two types of beacon each second using the android-beacon-library:
iBeacon type
custom beacon type
I am using the library since the 2.10 release and everything works fine.
But, when I try to implement the 2.16.2, 2.16.3 and 2.16.4 releases on my Samsung S8 (which is running on Android 9), I can't scan my Beacons when I turn off the location. I did not have this issue with the 2.16.1 release.
I also tried the reference app to check if I did something wrong, but I have the same bug with the reference app.
I may specify that I only have this issue with Samsung.
Thanks.
Recent versions of Android require multiple levels of location authorization for an app to detect beacons (bolded items show added requirements):
SDK 29+ (Android 10.0+)
Bluetooth must be turned on in settings
Location must be turned on in settings
Apps must have FINE_LOCATION permission in the manifest (COARSE_LOCATION is no longer sufficient)
Apps must ACCESS_BACKGROUND_LOCATION in the manifest to detect beacons when the app is not in the foreground with the screen on.
Apps must have dynamically obtained FINE_LOCATION permission from the user
Apps must have BLUETOOTH and BLUETOOTH_ADMIN permission in the manifest
SDK 23-28 (Android 6.0-9.x)
Bluetooth must be turned on in settings
Location must be turned on in settings
Apps must have COARSE_LOCATION permission or FINE_LOCATION permission in the manifest
Apps must have BLUETOOTH and BLUETOOTH_ADMIN permission in the manifest
Apps must have dynamically obtained COARSE_LOCATION permission or FINE_LOCATION permission from the user
SDK 18-22 (Android 4.3-Android 5.x)
Bluetooth must be turned on in settings
Apps must have COARSE_LOCATION permission or FINE_LOCATION permission in the manifest
Apps must have BLUETOOTH and BLUETOOTH_ADMIN permission in the manifest
The above restrictions have nothing specific to do with the Android Beacon Library -- they are an operating system requirement for any Bluetooth LE detection. If you see that some devices to not enforce these requirements under some conditions, then that is most likely an implementation hole on that specific platform. The more general rules still apply.

Is it possible to connect with estimote beacon without using location permission

I have an estimote beacon, i want to display a notification, when user comes in beacon range.
I was checking estimote beacon's android integration document, and found out that it requires location permission.
Estomote official app also does not work, if location permission is not granted.
My question is how to make beacon work without asking location permission, or if beacon does not work without location permission then what's the reason of using beacon, or am i missing something very important.
Android 6+ requires an app to obtain either COARSE_LOCATION or FINE_LOCATION permission at runtime in order to detect Bluetooth LE beacons or do Bluetooth LE scans at all. Without the permission, the OS blocks beacon detections. This is not an Estimote-specific issue -- it applies to scanning for any Bluetooth LE device.
This requirement was added to protect the privacy of users. The theory is that a runtime permission dialog makes it clear to a user that the app is accessing the user's location and ensures the user is aware of this and consents to the practice.

Enable to monitor beacon on android 6.0 using nexus 5 device

I am asking a follow up question to my previously asked question -> http://stackoverflow.com/questions/33607410/background-monitoring-of-eddystone-beacon-using-altbeacon-library-on-android-pla/33613116?noredirect=1#comment55139316_33613116.
Where i was able to successfully detect beacons both in the foreground and background until I found out that the same code was unable to detect the beacon when i try to run it on nexus 5 device running android 6.0.
Can anyone provide a explanation to why this is happening? Thanks.
Android 6.0 imposes two new requirements in order for apps to detect BLE Beacons:
Location Services must be turned on in settings. Settings -> Location -> On. The specific mode may be either "High Accuracy" or "Device Saving". This is a new requirement that appears to be being rolled out to all firmware builds from Google. Without this on, BLE scans discover no devices.
The app must be given runtime permissions by the user to ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION. You must code your app to present one of these permission requests to the user. If not granted, the app will not be able to detect BLE Beacons.
A detailed explanation of this process is in my blog post here: Is Your Beacon App Ready For Android 6.0?
With Android 6.0, you now need to request location permissions at runtime in order to be able to discover beacons.
From our initial tests: if your app targets SDK < 23 (i.e., pre-Android 6.0), you will only need these permissions to detect beacons in the background. If your app targets SDK >= 23 (i.e., Android 6.0 or later), you will need these permissions to detect beacons both in the background and in the foreground. You also need to have Location enabled on your Android 6.0 device for both cases.
Google has a detailed guide on how to implement checking for and requesting runtime permissions:
http://developer.android.com/training/permissions/requesting.html
Specifically, you need either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION. They both actually display the same message ("Allow APP_NAME to access your location?") to the user.

Why Android Marshmallow requires GPS to find iBeacons.?

I developed an app that work with iBeacons and this week i update it to work on Marshmallow. Until the update it didn't require GPS, but after the update it says that to find beacons in background it need gps. i don't find any reference on it. does someone know why Android Marshmallow requires GPS to find iBeacons?
I use altBeacon library to locate the beacons.
edit:
I'll clarify the question. Is the GPS involved in finding Beacons. Except for the permissions.
No, it is not necessary to have GPS turned on or even have a device with a GPS radio to detect beacons in Android 6. The GPS radio, if present is not activated when scanning for Bluetooth beacons.
The confusion comes from the fact that Android 6 newly requires apps to obtain either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions to be allowed to perform bluetooth scans. This change is simply motivated by informing users that bluetooth scanning can be used to infer their location (like with beacons). But the need to get this permission does not mean there is any technical dependency on the GPS radio. Consider that Android also can use WiFi access points and cell towers to infer location.
On some devices, notably the Nexus 5, there have been reports that disabling Location Services (Settings -> Location -> Off) disables the ability to scan for bluetooth devices. It is unclear whether this is a bug in that Nexus 5 build image or a new security restriction by Android that will be followed on other models in the future. See here for more info. Regardless, having the GPS radio on is not a requirement for Location Services being enabled.
Full disclosure: I am the lead developer on the Android Beacon Library open source project.
from http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html
To access the hardware identifiers of nearby external devices via
Bluetooth and Wi-Fi scans, your app must now have the
ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions:
It's not GPS as such that it needs, but because beacons are a technology that can also pin point your location, the location permission is required.
This is probably a permissions issue. iBeacon uses BT Low Energy, and in Android 6, you need location permission to initiate a scan:
To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions
Source: Android 6.0 changes

Categories

Resources