Enable to monitor beacon on android 6.0 using nexus 5 device

大城市里の小女人 提交于 2019-12-11 11:54:46

问题


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.


回答1:


Android 6.0 imposes two new requirements in order for apps to detect BLE Beacons:

  1. 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.

  2. 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?




回答2:


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.



来源:https://stackoverflow.com/questions/33690470/enable-to-monitor-beacon-on-android-6-0-using-nexus-5-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!