@@ -227,34 +227,19 @@ else if ((this.srcType == PHOTOLIBRARY) || (this.srcType == SAVEDPHOTOALBUM)) {
227227 //--------------------------------------------------------------------------
228228
229229 private String [] getPermissions (boolean storageOnly , int mediaType ) {
230- if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
231- if (storageOnly ) {
232- switch (mediaType ) {
233- case PICTURE :
234- return new String []{ Manifest .permission .READ_MEDIA_IMAGES };
235- case VIDEO :
236- return new String []{ Manifest .permission .READ_MEDIA_VIDEO };
237- default :
238- return new String []{ Manifest .permission .READ_MEDIA_IMAGES , Manifest .permission .READ_MEDIA_VIDEO };
239- }
240- }
241- else {
242- switch (mediaType ) {
243- case PICTURE :
244- return new String []{ Manifest .permission .CAMERA , Manifest .permission .CAMERA , Manifest .permission .READ_MEDIA_IMAGES };
245- case VIDEO :
246- return new String []{ Manifest .permission .CAMERA , Manifest .permission .READ_MEDIA_VIDEO };
247- default :
248- return new String []{ Manifest .permission .CAMERA , Manifest .permission .READ_MEDIA_IMAGES , Manifest .permission .READ_MEDIA_VIDEO };
249- }
250- }
251- } else {
252- if (storageOnly ) {
253- return new String []{Manifest .permission .READ_EXTERNAL_STORAGE , Manifest .permission .WRITE_EXTERNAL_STORAGE };
254- } else {
255- return new String []{Manifest .permission .CAMERA , Manifest .permission .READ_EXTERNAL_STORAGE , Manifest .permission .WRITE_EXTERNAL_STORAGE };
256- }
230+ ArrayList <String > permissions = new ArrayList <>();
231+
232+ if (android .os .Build .VERSION .SDK_INT <= Build .VERSION_CODES .R ) {
233+ // Android API 30 or lower
234+ permissions .add (Manifest .permission .READ_EXTERNAL_STORAGE );
235+ permissions .add (Manifest .permission .WRITE_EXTERNAL_STORAGE );
257236 }
237+ if (!storageOnly ) {
238+ // Add camera permission when not storage.
239+ permissions .add (Manifest .permission .CAMERA );
240+ }
241+
242+ return permissions .toArray (new String [0 ]);
258243 }
259244
260245 private String getTempDirectoryPath () {
@@ -381,7 +366,10 @@ private File createCaptureFile(int encodingType, String fileName) {
381366 throw new IllegalArgumentException ("Invalid Encoding Type: " + encodingType );
382367 }
383368
384- return new File (getTempDirectoryPath (), fileName );
369+ File cacheDir = new File (getTempDirectoryPath (), "org.apache.cordova.camera" );
370+ cacheDir .mkdir ();
371+
372+ return new File (cacheDir , fileName );
385373 }
386374
387375
@@ -529,7 +517,7 @@ private void processResultFromCamera(int destType, Intent intent) throws IOExcep
529517 if (this .allowEdit && this .croppedUri != null ) {
530518 writeUncompressedImage (croppedUri , galleryUri );
531519 } else {
532- if (Build .VERSION .SDK_INT <= 28 ) { // Between LOLLIPOP_MR1 and P, can be changed later to the constant Build.VERSION_CODES.P
520+ if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .P ) {
533521 writeTakenPictureToGalleryLowerThanAndroidQ (galleryUri );
534522 } else { // Android Q or higher
535523 writeTakenPictureToGalleryStartingFromAndroidQ (galleryPathVO );
@@ -1022,7 +1010,7 @@ private Bitmap getScaledAndRotatedBitmap(String imageUrl) throws IOException {
10221010 // Generate a temporary file
10231011 String timeStamp = new SimpleDateFormat (TIME_FORMAT ).format (new Date ());
10241012 String fileName = "IMG_" + timeStamp + (getExtensionForEncodingType ());
1025- localFile = new File (getTempDirectoryPath () + fileName );
1013+ localFile = new File (getTempDirectoryPath (), fileName );
10261014 galleryUri = Uri .fromFile (localFile );
10271015 writeUncompressedImage (fileStream , galleryUri );
10281016 try {
@@ -1408,7 +1396,7 @@ public Bundle onSaveInstanceState() {
14081396 }
14091397
14101398 if (this .imageUri != null ) {
1411- state .putString (IMAGE_URI_KEY , this .imageFilePath );
1399+ state .putString (IMAGE_URI_KEY , this .imageUri . toString () );
14121400 }
14131401
14141402 if (this .imageFilePath != null ) {
0 commit comments