Android Kotlin 上未授予位置
即使我允许在虚拟电话内访问位置,它仍然停留在“您需要授予访问位置的权限”。
override fun onRequestPermissionsResult(
requestCode: Int, permissions: Array<out String>, grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) {
1000 -> {
if (grantResults.isNotEmpty() &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission granted
} else {
// permission denied
Toast.makeText(this, "You need to grant permission to access location",
Toast.LENGTH_SHORT).show()
}
}
}
}
有什么想法吗?
Even though I allow location access within the virtual phone it is stuck on "You need to grant permission to access location".
override fun onRequestPermissionsResult(
requestCode: Int, permissions: Array<out String>, grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) {
1000 -> {
if (grantResults.isNotEmpty() &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission granted
} else {
// permission denied
Toast.makeText(this, "You need to grant permission to access location",
Toast.LENGTH_SHORT).show()
}
}
}
}
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Api 级别 31 的位置权限有点不同。
API 级别 31 的位置权限
您可以使用名为 EasyPermissions 让您的生活更轻松。
轻松实现权限
Location Permission for Api level 31 is a bit different.
Location permission for API level 31
You can use a library called EasyPermissions to make your life easier.
Easy Permission implementation