Skip to content

Commit

Permalink
permissions fix for camera and gallery access for android 13+
Browse files Browse the repository at this point in the history
  • Loading branch information
jclark118 committed Aug 31, 2023
1 parent 27944bd commit 72fd25d
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.graphics.BitmapFactory;
import android.media.Image;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
Expand Down Expand Up @@ -523,7 +524,7 @@ private Bitmap getImageResult(Uri uri){


/**
* Check permissions for camera use
* Check permissions for camera use. Note, only check write_external if < android 10
*/
public static boolean checkAndRequestPermissions(final Activity context) {
int writeExternalPermission = ContextCompat.checkSelfPermission(context,
Expand All @@ -534,9 +535,11 @@ public static boolean checkAndRequestPermissions(final Activity context) {
if (cameraPermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.CAMERA);
}
if (writeExternalPermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded
.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q){
if (writeExternalPermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded
.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(context, listPermissionsNeeded
Expand All @@ -555,19 +558,26 @@ public static boolean checkAndRequestPermissions(final Activity context) {
@Override
public void onRequestPermissionsResult(int requestCode, @NotNull String[] permissions, @NotNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
boolean flagged = false;
if (requestCode == REQUEST_ID_MULTIPLE_PERMISSIONS) {
if (ContextCompat.checkSelfPermission(FeatureViewActivity.this,
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(),
"FlagUp Requires Access to Camara.", Toast.LENGTH_SHORT)
"Camera permissions required", Toast.LENGTH_SHORT)
.show();

} else if (ContextCompat.checkSelfPermission(FeatureViewActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(),
"FlagUp Requires Access to Your Storage.",
Toast.LENGTH_SHORT).show();
} else {
flagged = true;
}
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(FeatureViewActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(),
"Storage permissions required",
Toast.LENGTH_SHORT).show();
flagged = true;

}
}
if(!flagged) {
takePicture();
}
}
Expand Down

0 comments on commit 72fd25d

Please sign in to comment.