Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Q java.io.FileNotFoundException: open failed: EACCES (Permission denied) #623

Closed
TarifHatoum opened this issue Feb 19, 2020 · 15 comments

Comments

@TarifHatoum
Copy link

Hi,

I have an issue related to the android 10 or Q in which when picking an image from gallery the app crashes and mentions java.io.FileNotFoundException: open failed: EACCES (Permission denied). While it is working normally for android devices below 29. Note that the target API in gradle is 29.

Kindly your kind support is appreciated.

@TarifHatoum
Copy link
Author

Any update?

@florian-do
Copy link

florian-do commented Feb 21, 2020

Same problem here, with the same target API

I've figure it out that if I launch the camera intent, go back and then retry to pick up a picture from the gallery it will work perfectly

val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, getCacheImagePath(f))
if (takePictureIntent.resolveActivity(f.requireActivity().packageManager) != null) {
    f.startActivityForResult(takePictureIntent, BFragment.REQUEST_CODE_CAMERA)
}

And after this it will work every time but if I uninstall / install the app it will not bug again

Edit:

Even with this in my Manifest :

<manifest ... >
    <!-- This attribute is "false" by default on apps targeting Android Q. -->
    <application android:requestLegacyExternalStorage="true" ... >
     ...
    </application>
</manifest>

@goyourfly
Copy link

Same problem

@TarifHatoum
Copy link
Author

Hi,
this requestLegacyExternalStorage="true" solve the issue but i need a solution for this because when android 11 it may not work. and note that i used a java language and not Koltin. Please if u can help me to solve the issue. Note that this code is working normally below Android 10.

private void openImagesDocument() {
Intent pictureIntent = new Intent(Intent.ACTION_GET_CONTENT);
pictureIntent.setType("image/*");
pictureIntent.addCategory(Intent.CATEGORY_OPENABLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
String[] mimeTypes = new String[]{"image/jpeg", "image/png"};
pictureIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
}
startActivityForResult(Intent.createChooser(pictureIntent, "Select Picture"), PICK_IMAGE_GALLERY_REQUEST_CODE);
}

private void openCropActivity(Uri sourceUri, Uri destinationUri) {

    UCrop.Options options = new UCrop.Options();
    options.setCircleDimmedLayer(true);


    options.setActiveWidgetColor(ContextCompat.getColor(getContext(), R.color.black));
    //options.setStatusBarColor(ContextCompat.getColor(getContext(), R.color.ToolbarcolorPrimary));
    // options.setDimmedLayerColor(ContextCompat.getColor(getContext(), R.color.ToolbarcolorPrimary));
    //options.setToolbarColor(ContextCompat.getColor(getContext(), R.color.white));
    options.setRootViewBackgroundColor(ContextCompat.getColor(getContext(), R.color.ToolbarcolorPrimary));
    options.setToolbarWidgetColor(ContextCompat.getColor(getContext(), R.color.white));
    // options.setCropFrameColor(ContextCompat.getColor(getContext(), R.color.ToolbarcolorPrimary));
    //options.setCropGridColor(ContextCompat.getColor(getContext(), R.color.ToolbarcolorPrimary));
    // options.setLogoColor(ContextCompat.getColor(getContext(), R.color.black));


    options.setToolbarColor(ContextCompat.getColor(getContext(), R.color.ToolbarcolorPrimary));
    options.setStatusBarColor(ContextCompat.getColor(getContext(), R.color.ToolbarcolorPrimary));
    options.setMaxBitmapSize(10000);
    options.setCompressionQuality(100);
    UCrop.of(sourceUri, destinationUri)
            .withOptions(options)
            .withMaxResultSize(300, 300)
            .withAspectRatio(50f, 50f)
            .start(getContext(), this);
}

public void onActivityResult(int requestCode, int resultCode, @nullable Intent data) {
if (requestCode == PICK_IMAGE_GALLERY_REQUEST_CODE && resultCode == getActivity().RESULT_OK && data != null) {
try {
Uri sourceUri = data.getData();
File file = getImageFile();
Uri destinationUri = Uri.fromFile(file);
openCropActivity(sourceUri, destinationUri);

        } catch (Exception e) {
            toast(getActivity(), "Please select another image");
        }

}

private File getImageFile() throws IOException {
File storageDir = new File(getContext().getExternalFilesDir(null), "/profile.jpg");
currentPhotoPath = getContext().getExternalFilesDir(null) +"/profile.jpg";
return storageDir;
}

@TarifHatoum
Copy link
Author

Hi
is there any update since I'm upgrading the android studio to android-R and still crashing issue

regards

@TarifHatoum
Copy link
Author

Hi
is there any update since I'm upgrading the android studio to android-R and still crashing issue in device samsung note 9 API version 11

regards

@RakeshrajRocs
Copy link

Using requestLegacyExternalStorage="true" in manifest leads to AAPT error during build

@friederikewild
Copy link

friederikewild commented Mar 12, 2020

This might be a duplicate or related to #598

@p1nkydev
Copy link
Contributor

Duplicate #598 would be fixed soon.

@t2314862168
Copy link

i changed some code and solved the problem
BitmapCropTask.java

@TarifHatoum
Copy link
Author

TarifHatoum commented Apr 20, 2020 via email

@t2314862168
Copy link

@Anonymous123456789123 emm , here is sample uCrop-2.2.4 ,just clone down and enjoy it

@Drjacky
Copy link
Contributor

Drjacky commented May 3, 2021

@t2314862168 Could you please make a pull request and add your changes to the origin repo?

@yozhik
Copy link

yozhik commented May 21, 2021

Here what Google write about this:
https://support.google.com/googleplay/android-developer/answer/10467955#zippy=%2Cpermitted-uses-of-the-all-files-access-permission%2Cexceptions%2Cinvalid-uses%2Calternatives-to-common-uses

We have to use: Media Store API or storage access framework to be able to run our apps on Android 11+, other ways - Google will block our accounts. Or one can write Google a message and tell why he/she can't use new API for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants