Prompting for location permission when NOT monitoring in background?

蓝咒 提交于 2019-12-04 04:50:23

To clarify the requirement is different depending on whether you set targetSdkVersion 23 in your build.gradle file.

If you target SDK 23 (Marshmallow) or higher:

  • You must declare android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION in your manifest.
  • You must prompt a user for permission as described in my blog post here.
  • The user must accept this permission and not turn it off.
  • If any of the above requirements are not met, you won't be able to detect beacons in the foreground or the background.

If you target SDK 22 or lower:

  • You may optionally declare android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION in your manifest.
  • The user may turn on or off the permission by going to settings.
  • If one of the permissions is not granted, you will still be able to detect beacons in the foreground, but not in the background.

See here and here for more details.

I had the same issue with my app when I tested it on a Marshmallow device. To avoid prompting the user for permission, I just changed the targetSdkVersion to 22. The compileSdkVersion can remain at 23. After you change build.gradle, you may need to run Tools > Android > Sync Project with Gradle Files. If you use Eclipse, the targetSdkVersion is in the manifest file.

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