+ boolean havePermission(String permission) {
+
+ if (Build.VERSION.SDK_INT < 16) {
+ return true;
+ }
+
+ if (permissionGranted(permission)) {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ private boolean permissionGranted(String permission) {
+ boolean check = ContextCompat.checkSelfPermission(app, permission) ==
+ PackageManager.PERMISSION_GRANTED;
+ return check;
+ }
+
+ public Object[] checkThenLoadRandomImage (int target_width, int target_height,
+ boolean rotate_p) {
+ // RES introduced in API 16
+ String permission = Manifest.permission.READ_EXTERNAL_STORAGE;
+
+ if (havePermission(permission)) {
+ return loadRandomImage(target_width,target_height,rotate_p);
+ } else {
+ return null;
+ }
+ }
+