Search code examples
androidkotlinandroid-cameraandroid-manifestandroid-permissions

is there any way to change the default message of RequestPermission() in Android using kotlin?


I'm developping an app that requires the Camera permission to record videos. However, in the default notification message, it says

"Allow my_app to take pictures and record videos?"

which is a bit unaccurate, as the app doesn't let you take pictures.

This is my code to check for those permissions (already defined in the manifest file):

val requestPermissionLauncher =
            registerForActivityResult(
                ActivityResultContracts.RequestPermission()
            ) { isGranted: Boolean ->
                if (isGranted) {
                    Log.i("Permission: ", "Granted")
                } else {
                    Log.i("Permission: ", "Denied")
                }
            }
        when {
            ContextCompat.checkSelfPermission(
                requireContext(),
                Manifest.permission.CAMERA
            ) == PackageManager.PERMISSION_GRANTED -> {
            }
            else -> {
       

                requestPermissionLauncher.launch(
                    Manifest.permission.CAMERA,
                )

            }
        }

but then, I do:

val intent2 = Intent(MediaStore.ACTION_VIDEO_CAPTURE)

in my code because that's what I need, so the message may confuse the user. Is there any way to solve this?


Solution

  • No, you can't change the text in the permission dialogs. If this were allowed this would be a security risk. Although your app doesn't specifically take pictures, the permission would allow you to do so, so the messaging is correct. If the user confirms the permission, your app will be able to record videos and take pictures.

    It is best practice to only ask for permissions right when a user is about to do an action that actually requires it as opposed to ask for it at the start of an app. This is a good time to explain to the user beforehand, why you require the permission. You can do so through a self-made tutorial screen or your own dialogue. But the actual permission dialogue will stay the same.