vmadalin / easypermissions-ktx

🔓 Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.
https://firebaseopensource.com/projects/googlesamples/easypermissions/
Apache License 2.0
380 stars 38 forks source link

FOREGROUND_SERVICE_MICROPHONE doesn't show any prompt. This is a new permission for android 14 and above. #23

Closed ronenfe closed 1 month ago

ronenfe commented 1 month ago
 private fun requestPermissions() {
        val perms = mutableListOf(
            ACCESS_FINE_LOCATION,
            RECORD_AUDIO, // Add microphone permission
        )
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            perms.add(POST_NOTIFICATIONS)
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
            perms.add(FOREGROUND_SERVICE_MICROPHONE)
        }
        val permsToRequest = mutableListOf<String>()
        val rationaleMessages = mutableListOf<String>()

        // Check which permissions are missing and need to be requested
        for (perm in perms) {
            if (!EasyPermissions.hasPermissions(this, perm)) {
                permsToRequest.add(perm)
                // Add rationale messages for missing permissions
                when (perm) {
                    ACCESS_FINE_LOCATION -> rationaleMessages.add(getString(R.string.permission_location_rationale))
                    RECORD_AUDIO -> rationaleMessages.add(getString(R.string.permission_record_audio_rationale))
                    POST_NOTIFICATIONS -> rationaleMessages.add(getString(R.string.permission_notifications_rationale))
                    FOREGROUND_SERVICE_MICROPHONE -> rationaleMessages.add(getString(R.string.permission_record_audio_in_background_rationale))
                }
            }
        }
ronenfe commented 1 month ago

I think this is as designed. and you can use either one: RECORD_AUDIO or FOREGROUND_SERVICE_MICROPHONE , it has the same prompt, no need to use both.