Simplest Way To Ask Permissions Without Using Third Party Library
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
//add list of permissions that you want | |
val permissions = arrayOf( | |
Manifest.permission.READ_EXTERNAL_STORAGE, | |
Manifest.permission.WRITE_EXTERNAL_STORAGE | |
) | |
/** | |
* Method to ask permissions | |
*/ | |
private fun checkPermissions(): Boolean { | |
var result: Int | |
val listPermissionsNeeded = java.util.ArrayList<String>() | |
for (p in permissions) { | |
result = ContextCompat.checkSelfPermission(this, p) | |
if (result != PackageManager.PERMISSION_GRANTED) { | |
listPermissionsNeeded.add(p) | |
} | |
} | |
if (!listPermissionsNeeded.isEmpty()) { | |
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toTypedArray(), 100) | |
return false | |
} | |
return true | |
} |
Simplest way to ask run time permission in android without using third party library.
No comments :
Post a Comment