Created
May 23, 2019 10:26
-
-
Save AlaaEddinAlbarghoth/eeacd9051c838f8a14efd068e185d11f to your computer and use it in GitHub Desktop.
Using Dexter for Permission in Android
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
| 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