Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileNotFoundException: open failed: EACCES (Permission denied)

Tags:

java

android

In emulator (i use genymotion) it works fine, but when I run it on a real device (my phone is ASUS ZenFone Laser 5.0) throws a filenotfoundexception

java.io.FileNotFoundException: /storage/emulated/0/cam20160926_075819.jpg: open failed: EACCES (Permission denied)

imgBitmap = MediaStore.Images.Media.getBitmap(cr, selectedImage);

here's the method onActivityResult()

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode){
            case CAMERA_REQUEST:
                if (resultCode == Activity.RESULT_OK){
                    Uri selectedImage = imageUri;
                    getActivity().getContentResolver().notifyChange(selectedImage, null);
                    ContentResolver cr = getActivity().getContentResolver();
                    Bitmap imgBitmap;
                    try {
                        imgBitmap = MediaStore.Images.Media.getBitmap(cr, selectedImage);

                        accountPhoto.setImageBitmap(imgBitmap);
                    } catch (IOException e) {
                        e.printStackTrace();
                        Toast.makeText(getActivity().getApplicationContext(), "Something went wrong while taking a photo", Toast.LENGTH_LONG).show();
                        Log.e("Camera", e.toString());
                    }

                }
        }
    }

i read some related questions and solutions about this EACCES, and it seems the problem is on my permission:

<uses-feature android:name="android.hardware.camera2" android:required="true"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

am I missing something? thanks for responding

like image 595
Jarvis Millan Avatar asked Sep 26 '16 00:09

Jarvis Millan


People also ask

How do I fix Open failed Eacces permission denied?

Just turn off USB storage, and with the correct permissions, you'll have the problem solved. Save this answer.

What is Eacces permission denied?

It looks like you're running into permission issues. If you are installing npm-packages then it might possible that you are getting an EACCES error when trying to install a package globally. This means you do not have permission to write to the directories npm uses to store global packages and commands.

How do you fix exception Open failed Eacces permission denied on Android 11 12?

MANAGE_EXTERNAL_STORAGE"/> in the manifest file and try to get the file access permission in the android 11 phones. Then you will open and read the file from the storage. if you are working with android 11 and working on a file then you have to use MANAGE_EXTERNAL_STORAGE permission.


1 Answers

you have to request permission before you start your instructions because this permission is considered dangerous in Marshmallow:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) 
     {
      requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, RESULT);
     } 
    else
     {
    //your code
     }
like image 165
Khalil M Avatar answered Oct 31 '22 04:10

Khalil M