Request permission to send PUSH notifications in Compose and Android 13

247 Views Asked by At

A slightly non-trivial task: the project goes to MVI + orbit and a task has appeared to request permission to send push notifications. But the question is, what is the best way to do it? Conditionally, a dialog appears in which there are 2 buttons "Cancel" and "Settings". When the user clicks on "Settings" -> it must be transferred to the device settings to activate PUSH notifications. If the user has allowed notifications, then we do some action. The problem is that when you click on "Settings", a method is called from the ViewModel and from there the postSideEffect, in which a request to allow push notifications should already be made. How can I do that? Thank you in advance!

P.S. It is also necessary to somehow keep track that the user already has permission and not call up a dialog that offers to get it.

My code:

viewModel.collectSideEffect { sideEffect ->
    when (sideEffect) {
    ...
    SideEffect.OpenSettings -> {
         // write logic here and somehow save in state information that permission has been received
    }
    ...
}
0

There are 0 best solutions below