Use to request permission to access confidential user data.
Android applications must request permission to access the user's confidential data. This library allows you to quickly implement the logic to obtain permissions to access user data, as well as to certain system functions.
by gradle :
dependencies {
implementation 'com.cleveroad.bootstrap:kotlin-permissionrequest:2.0.0'
}
class CheckPermissionsFragment : BaseLifecycleFragment<CheckPermissionsVM>(), View.OnClickListener {
companion object {
private const val CAMERA_REQUEST_CODE = 10002
}
private val permissionRequest: PermissionRequest = PermissionRequest()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) =
super.onViewCreated(view, savedInstanceState).also {
setClickListeners(bOpenCamera)
}
override fun onRequestPermissionsResult(requestCode: Int,
permissions: Array<String>,
grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
permissionRequest.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
override fun onClick(view: View) {
when (view.id) {
R.id.bOpenCamera -> checkPermission { openCamera() }
}
}
private fun checkPermission(block: () -> Unit = {}) {
permissionRequest.request(this,
CAMERA_REQUEST_CODE,
arrayOf(Manifest.permission.CAMERA),
object : PermissionResult {
override fun onPermissionGranted() {
block()
}
})
}
private fun openCamera() {
...
}
}
If you have any questions, issues or propositions, please create a new issue in this repository.
If you want to hire us, send an email to [email protected] or fill the form on contact page
Follow us:
The MIT License (MIT)
Copyright (c) 2016 Cleveroad Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.