-
-
Save Chandu4221/e2763ca9d00a433c622a6992fdb551e5 to your computer and use it in GitHub Desktop.
RequestPermission.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| request_permission.setOnClickListener { | |
| requestPermission.launch(permission.BLUETOOTH) | |
| } | |
| request_multiple_permission.setOnClickListener { | |
| requestMultiplePermissions.launch( | |
| arrayOf( | |
| permission.BLUETOOTH, | |
| permission.NFC, | |
| permission.ACCESS_FINE_LOCATION | |
| ) | |
| ) | |
| } | |
| // Request permission contract | |
| private val requestPermission = | |
| registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted -> | |
| // Do something if permission granted | |
| if (isGranted) toast("Permission is granted") | |
| else toast("Permission is denied") | |
| } | |
| // Request multiple permissions contract | |
| private val requestMultiplePermissions = | |
| registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions : Map<String, Boolean> -> | |
| // Do something if some permissions granted or denied | |
| permissions.entries.forEach { | |
| // Do checking here | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment