From dd57d9fc5235f88e9c287721f1bc87128958b0ff Mon Sep 17 00:00:00 2001 From: ChrisTomAlx Date: Thu, 11 Feb 2021 13:26:55 +0530 Subject: [PATCH] possible fix for android 11 external storage issues --- .../src/main/java/com/scanlibrary/PickImageFragment.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/scanlibrary/PickImageFragment.java b/library/src/main/java/com/scanlibrary/PickImageFragment.java index b11c7b9..fe6b068 100644 --- a/library/src/main/java/com/scanlibrary/PickImageFragment.java +++ b/library/src/main/java/com/scanlibrary/PickImageFragment.java @@ -34,6 +34,7 @@ */ public class PickImageFragment extends Fragment { int camorgal = 0; + private String imagePath = ""; private View view; private ImageButton cameraButton; private ImageButton galleryButton; @@ -62,6 +63,7 @@ private void init() { cameraButton.setOnClickListener(new CameraButtonClickListener()); galleryButton = (ImageButton) view.findViewById(R.id.selectButton); galleryButton.setOnClickListener(new GalleryClickListener()); + imagePath = getActivity().getApplicationContext().getExternalCacheDir().getPath() + "/scanSample"; if (isIntentPreferenceSet()) { handleIntentPreference(); } else { @@ -71,7 +73,7 @@ private void init() { private void clearTempImages() { try { - File tempFolder = new File(ScanConstants.IMAGE_PATH); + File tempFolder = new File(imagePath); for (File f : tempFolder.listFiles()) f.delete(); } catch (Exception e) { @@ -148,7 +150,7 @@ private File createImageFile() { clearTempImages(); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); - File file = new File(ScanConstants.IMAGE_PATH, "IMG_" + timeStamp + + File file = new File(imagePath, "IMG_" + timeStamp + ".jpg"); fileUri = Uri.fromFile(file); return file;