Created
July 15, 2019 14:45
-
-
Save aasumitro/066101434396c2138d3b6ec3062236c9 to your computer and use it in GitHub Desktop.
SimplePermission.kt
This file contains 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
enum class PermissionState { GRANTED, NOT_GRANTED, REJECTED } | |
fun checkPermissionState( | |
activity: Activity, | |
permissionName: String | |
) = when { | |
ContextCompat.checkSelfPermission(activity, permissionName) | |
== PackageManager.PERMISSION_GRANTED -> PermissionState.GRANTED | |
ActivityCompat.shouldShowRequestPermissionRationale( | |
activity, | |
permissionName | |
) -> PermissionState.REJECTED | |
else -> PermissionState.NOT_GRANTED | |
} | |
fun requestPermission( | |
activity: Activity, | |
permissionName: String | |
) = ActivityCompat.requestPermissions( | |
activity, | |
arrayOf(permissionName), | |
MainActivity.PERMISSION_REQUEST_CODE | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment