Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AlaaEddinAlbarghoth/eeacd9051c838f8a14efd068e185d11f to your computer and use it in GitHub Desktop.

Select an option

Save AlaaEddinAlbarghoth/eeacd9051c838f8a14efd068e185d11f to your computer and use it in GitHub Desktop.
Using Dexter for Permission in Android
In Manifest file:
<uses-permission android:name="android.permission.CAMERA"/>
In the build.gradle(Module):
/**
* dependency to request the runtime permissions.
*/
implementation "com.karumi:dexter:5.0.0"
In the Code:
//region Util
private fun requestingMultiplePermissions() {
Dexter.withActivity(this)
.withPermissions(
permission.CAMERA
)
.withListener(object : MultiplePermissionsListener {
override fun onPermissionsChecked(report: MultiplePermissionsReport) {
// check if all permissions are granted
if (report.areAllPermissionsGranted()) {
// do you work now
}
}
// check for permanent denial of any permission
if (report.isAnyPermissionPermanentlyDenied) {
// permission is denied permanently, navigate user to app settings
showMessage("permission is denied permanently")
}
}
override fun onPermissionRationaleShouldBeShown(
permissions: List<PermissionRequest>,
token: PermissionToken
) {
token.continuePermissionRequest()
}
})
.onSameThread()
.check()
}
// endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment