Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the flow strange? #24

Open
ronenfe opened this issue Oct 28, 2024 · 0 comments
Open

Why is the flow strange? #24

ronenfe opened this issue Oct 28, 2024 · 0 comments

Comments

@ronenfe
Copy link

ronenfe commented Oct 28, 2024

in onCreate():

   `Handle service binding and starting
    if (hasPermissions()) {
        startOrBindService()
    }
    
        private fun hasPermissions() :Boolean {
    if (EasyPermissions.hasPermissions(this, *permissions.toTypedArray())) {
        return true
    }
    else{
        val permsToRequest = mutableListOf<String>()
        val rationaleMessages = mutableListOf<String>()

        // Check which permissions are missing and need to be requested
        for (perm in permissions) {
            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))
                }
            }
        }
        EasyPermissions.requestPermissions(
            this,
            rationaleMessages.joinToString("\n\n"),
            REQUEST_CODE_PERMISSIONS,
            *permsToRequest.toTypedArray()
        )
        return false
    }
}

    override fun onPermissionsDenied(requestCode: Int, perms: List<String>) {
    setupViews()
    setSlidersProperties()
    setPausePlayImage()
}
override fun onPermissionsGranted(requestCode: Int, perms: List<String>) {
    if (EasyPermissions.hasPermissions(this, *permissions.toTypedArray())) {
        if (!isServiceBound)
            startOrBindService()
        else {
            mIsPaused = mSharedPref.getBoolean(KEY_IS_PAUSED, true)
            setupViews()
            setSlidersProperties()
            setPausePlayImage()
        }
    }
}

`
First time opening the app, android permissions request appear.
Denying the permissions raise the easypermission rationale.
Clicking Ok in the dialog, raises the Android permissions requests again.
Denying permission again will not raise the rationale ever again even when app is restarted and haspermission() called again.
If Cancel button is pressed in the dialog it just closes the rationale and it will keep appearing.

I would expect the following behavior:
First time opening the app, rationale appears
Cancel button pressed: No permission requests shown. Ok button pressed: pemission requests shown.
Denying the permissions raises the easypermission rationale again everytime.

Code and logs

// TODO(you): show the code that produces the problem,
//            and any relevant logs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant