Skip to content

Instantly share code, notes, and snippets.

@Kashif-E
Created December 30, 2020 12:34
Show Gist options
  • Save Kashif-E/55b582240ed8bcf7217cfe07aed6c33c to your computer and use it in GitHub Desktop.
Save Kashif-E/55b582240ed8bcf7217cfe07aed6c33c to your computer and use it in GitHub Desktop.
private fun getPermission() {
Dexter.withContext(this)
.withPermissions(
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE
).withListener(object : MultiplePermissionsListener {
override fun onPermissionsChecked(report: MultiplePermissionsReport) {
report.let {
if (report.areAllPermissionsGranted()) {
Toast.makeText(this@MainActivity, "Permissions Granted", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this@MainActivity, "Please Grant Permissions to use the app", Toast.LENGTH_SHORT).show()
}
}
}
override fun onPermissionRationaleShouldBeShown(permissions: List<PermissionRequest?>?, token: PermissionToken?) {
token?.continuePermissionRequest()
}
}).withErrorListener{
Toast.makeText(this, it.name, Toast.LENGTH_SHORT).show()
}.check()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment