Permission Manager module simply process the given permissions and lets you decide what to do after the permissions are granted or denied.
Include the library in your build.gradle
dependencies {
implementation 'com.sarafinmahtab:permissionmanager:1.0'
}
<dependency>
<groupId>com.sarafinmahtab</groupId>
<artifactId>permissionmanager</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
<dependency org="com.sarafinmahtab" name="permissionmanager" rev="1.0">
<artifact name="permissionmanager" ext="pom"></artifact>
</dependency>
Initialize Permission Manager in your activity
var permissionManager = PermissionManager(this)
You need to send a requestcode
and your list of permissions
or single permission
.
Then PermissionManager will do the rest of the part. And send the response onRequestPermissionsResult
permissionManager.checkForPermission(
REQUEST_PERMISSION,
arrayOf(
android.Manifest.permission.CAMERA,
android.Manifest.permission.ACCESS_FINE_LOCATION
)
)
Check if your selected permissions is already granted
permissionManager.hasPermission(
arrayOf(
android.Manifest.permission.CAMERA,
android.Manifest.permission.ACCESS_FINE_LOCATION
)
)
Decide what to do with the permission request result
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == REQUEST_PERMISSION) {
if (permissionManager.allPermissionGranted(grantResults)) {
updatePermissionStatus("Granted Permissions")
} else {
updatePermissionStatus("Cancelled Permissions")
}
}
}
Set Custom Dialog for Permission Request Explanation
permissionManager.setPermissionExplanationDialog(
title = "Permission Need",
message = "Please accept permission",
drawableId = null
)