位置权限 android
In this tutorial, we’ll be discussing and implementing the new location permissions model in our android application.
在本教程中,我们将在android应用程序中讨论和实现新的位置权限模型。
Android 10位置权限 (Android 10 Location Permissions)
With the introduction of Android 10, besides the dialog UI, the way of handling location permissions has also changed.
Now the user is allowed to choose whether they want location updates when the app is in the background.
For that a new permission needs to be declared in the Manifest file:
随着Android 10的引入,除了对话框UI之外,处理位置权限的方式也发生了变化。
现在,允许用户选择在后台运行应用程序时是否要更新位置。
为此,需要在清单文件中声明新的权限:
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
Calling this along with COARSE_LOCATION would pop up a dialog with three options:
与COARSE_LOCATION一起调用将弹出一个带有三个选项的对话框:
- Always Allow 总是允许
- Allow only while using the app 仅在使用应用程序时允许
- Deny 拒绝
On selecting Deny, the next time the dialog will show a fourth option – Deny & Do Not Ask Again.
在选择“拒绝”时,下一次对话框将显示第四个选项-“拒绝并不再询问”。
Always Allow ensures that you can poll for location updates in foreground and background.
始终允许确保您可以轮询前景和后台的位置更新。
If you select “Allow only while using the app”, the next time the permission dialog will only ask you to always allow the location permission or deny.
如果您选择“仅在使用应用程序时允许”,则下次权限对话框将仅要求您始终允许位置权限或拒绝。
In the following sec