Skip to content

Instantly share code, notes, and snippets.

@UtkuGlsvn
Created August 2, 2023 18:10
Show Gist options
  • Save UtkuGlsvn/391488f606d3afeeb86d0962aff8d14d to your computer and use it in GitHub Desktop.
Save UtkuGlsvn/391488f606d3afeeb86d0962aff8d14d to your computer and use it in GitHub Desktop.
Android multi permission function
private fun checkNotificationPermission(): Boolean {
val permissions = arrayOf(
Manifest.permission.POST_NOTIFICATIONS,
Manifest.permission.ACCESS_COARSE_LOCATION
)
val isAllPermissionsGranted = permissions.all {
this.checkSelfPermission(it) == PackageManager.PERMISSION_GRANTED
}
if (!isAllPermissionsGranted) {
this.requestPermissions(permissions, 1)
}
return isAllPermissionsGranted
}
@UtkuGlsvn
Copy link
Author

val isPermissionGranted = checkNotificationPermission()

    // If the permission is not granted, show a dialog to request it
    if (!isPermissionGranted) {
        requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), 1)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment