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):
Java
private static boolean checkPermission(Activity ac) {
ContentResolver contentResolver = ac.getContentResolver();
Uri uri = Uri.parse("content://com.anready.croissant.files")
.buildUpon()
.appendQueryParameter("command", "isPermissionsGranted")
.build();
Cursor cursor = null;
try {
cursor = contentResolver.query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
int dataIndex = cursor.getColumnIndex("response");
if (dataIndex == -1) {
System.out.println("Data column not found");
return false;
}
JSONArray jsonArray = new JSONArray(cursor.getString(dataIndex));
return jsonArray.getJSONObject(0).getBoolean("result");
} else {
System.out.println("Error while getting data!");
}
} catch (Exception e) {
System.out.println("Error while getting data!\n" + e.getMessage());
} finally {
if (cursor != null) {
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