我试图通过在权限对话框中处理近似位置的情况来符合 Android 12 对位置权限的更改。但是当在带有 Android S (android-S\google_apis\x86_64) 的枚举器上运行它时,我仍然得到与以前版本的 android 相同的对话框:
这是我的设置:
android {
compileSdkVersion "android-S"
buildToolsVersion "30.0.3"
defaultConfig {
minSdkVersion 23
targetSdkVersion "S"
...
}
...
}
按照文档中的确切示例:https ://developer.android.com/about/versions/12/approximate-location
val locationPermissionRequest = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permissions ->
when {
permissions.getOrDefault(Manifest.permission.ACCESS_FINE_LOCATION, false) -> {
// Precise location access granted.
}
permissions.getOrDefault(Manifest.permission.ACCESS_COARSE_LOCATION, false) -> {
// Only approximate location access granted.
} else -> {
// No location access granted.
}
}
}
locationPermissionRequest.launch(arrayOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION))
知道获取新位置权限对话框缺少什么吗?
编辑:
Build.VERSION.SDK_INT = 30
Build.VERSION.RELEASE = "11"
Build.VERSION.PREVIEW_SDK_INT = 1
Build.VERSION.RELEASE_OR_CODENAME = "S"