Skip to content

Commit

Permalink
camera:basic: don't request WRITE_EXTERNAL_STORAGE
Browse files Browse the repository at this point in the history
Not needed for writing to the SD card since KitKat, and the permission
is auto-denied for targetSdkVersion 33+:
https://developer.android.com/reference/android/Manifest.permission#WRITE_EXTERNAL_STORAGE

This isn't really the right way to do this though. We're supposed to do
https://developer.android.com/training/data-storage/use-cases?utm_source=lint&utm_medium=lint&utm_campaign=lint#capture-image-media

Fixes #1031
  • Loading branch information
DanAlbert committed May 15, 2024
1 parent 9400c7f commit ba3fd32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion camera/basic/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
android:versionName="1.0">
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="false"
android:fullBackupContent="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,15 @@ public void RequestCamera() {
Log.e(DBG_TAG, "Found legacy camera Device, this sample needs camera2 device");
return;
}
String[] accessPermissions = new String[] {
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
boolean needRequire = false;
for(String access : accessPermissions) {
int curPermission = ActivityCompat.checkSelfPermission(this, access);
if(curPermission != PackageManager.PERMISSION_GRANTED) {
needRequire = true;
break;
}
}
if (needRequire) {
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.CAMERA
) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
accessPermissions,
PERMISSION_REQUEST_CODE_CAMERA);
new String[]{Manifest.permission.CAMERA},
PERMISSION_REQUEST_CODE_CAMERA
);
return;
}
notifyCameraPermission(true);
Expand Down

0 comments on commit ba3fd32

Please sign in to comment.