Component - Permission request flow
This UI component handles asking the user for permission to access a feature, like the camera or location. It shows a button to request permission and displays the current permission status.
This UI component handles asking the user for permission to access a feature, like the camera or location. It shows a button to request permission and displays the current permission status.
ConstraintLayout ├── TextView (Permission Status) └── Button (Request Permission)
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 101 && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
println("Permission granted")
} else {
println("Permission denied")
}
}
What will be printed if the user denies the permission?ActivityCompat.requestPermissions(this, Manifest.permission.ACCESS_FINE_LOCATION, 200)
Pass the test and this pattern moves unknown