Hemant Tiwari
Hemant Tiwari

Reputation: 145

Is it possible to get a callback when a permission is granted to an application in Android

Android M has introduced Runtime permission model.
checkPermission() method of Package Manager can be used to know if a permission is granted to an application.
Is it also possible to get a callback in application, when user grants/revokes permission ?
So that a feature dependent on that permission can be enabled/disabled.

Upvotes: 3

Views: 2612

Answers (2)

Drunken Daddy
Drunken Daddy

Reputation: 7991

When user grants permission via settings and comes back to the app, onResume() will be called. You can check for the permissions within onResume.

override fun onResume() {
    super.onResume()
    if (_navigatedToSettings == true) { // set this to true before you open settings
         _navigatedToSettings = false
         PermissionUtils.askForCameraAndAudioPermissions(this)
    }  
}

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1006744

Is it also possible to get a callback in application, when user grants/revokes permission ?

If you are requesting permissions with requestPermission(), your callback is onRequestPermissionResult().

If the user revokes permissions via Settings, your callback is onCreate(), as Android will terminate your process.

If the user grants permissions via Settings, you do not find out about that, until your next call to checkSelfPermission(). There is no callback for this scenario.

Upvotes: 8

Related Questions