Been Googling, followed the documentation. The dialogue doesn't show up at all. I put the uses-permission in the manifest. I don't understand what I am doing wrong. I get to the else branch where it is supposed to launch the permission, but nothing shows up. This seems like such a simple thing but I can't get it to work. Any help would be great.
This is my code from my main activity:
private val requestPermissionLauncher =
registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
Log.d(TAG, "Permission granted.")
} else {
Log.d(TAG, "Permission denied.")
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
when (PackageManager.PERMISSION_GRANTED) {
ContextCompat.checkSelfPermission(
applicationContext,
Manifest.permission.READ_EXTERNAL_STORAGE
) -> {
Log.d(TAG, "Permission denied.")
// You can use the API that requires the permission.
}
else -> {
Log.d(TAG, "Permission denied, launcher launched.")
// You can directly ask for the permission.
// The registered ActivityResultCallback gets the result of this request.
requestPermissionLauncher.launch(
Manifest.permission.READ_EXTERNAL_STORAGE
)
}
}
}