Getting permissions
Let's find out if the Croissant app has permission to read (for Android 10 and below) and full file management (for Android 11 and above).
This method will be return a status of permissions (is Croissant have it or no):
Kotlin
private fun checkPermission(ac: Activity): Boolean {
val contentResolver: ContentResolver = ac.contentResolver
val uri = Uri.parse("content://com.anready.croissant.files")
.buildUpon()
.appendQueryParameter("command", "isPermissionsGranted") // Adding parameter command
.build()
var cursor: Cursor? = null
try {
cursor = contentResolver.query(uri, null, null, null, null)
if (cursor != null && cursor.moveToFirst()) {
val dataIndex = cursor.getColumnIndex("response")
if (dataIndex == -1) {
println("Error while getting data!")
return false
}
val jsonArray = JSONArray(cursor.getString(dataIndex))
val fileInfo = jsonArray.getJSONObject(0)
return fileInfo.getBoolean("result")
} else {
println("Error while getting data!")
}
} catch (e: Exception) {
println("Error while getting data!\n" + e.message)
} finally {
cursor?.close()
}
return false
}
By calling this method: checkPermission(this). It will return true or false, true means permissions have been received, false means there are no permissions, and in the future you will receive error 01 when calling the API (See the article Errors)
That's it! Go to the next page