I\'m trying to get the GPS coordinates to display when I click a button in my activity layout. The following is the method that gets called when I click the button:
If you simply want to check for permissions (rather than request for permissions), I wrote a simple extension like so:
fun BaseActivity.checkPermission(permissionName: String): Boolean {
return if (Build.VERSION.SDK_INT >= 23) {
val granted =
ContextCompat.checkSelfPermission(this, permissionName)
granted == PackageManager.PERMISSION_GRANTED
} else {
val granted =
PermissionChecker.checkSelfPermission(this, permissionName)
granted == PermissionChecker.PERMISSION_GRANTED
}
}
Now, if I want to check for a permission I can simply pass in a permission like so:
checkPermission(Manifest.permission.READ_CONTACTS)