2

I am trying to create bitmap from photo path like this:

    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);

And I have added permissions in manifest:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

It works fine before. But suddenly it got a problem, says:

    E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/image_1.jpg: open failed: EACCES (Permission denied)

I have been searching the answer for a few days, but still can not figure it out. I am totally new to android and this is my first post. Hope you can help me with it. Thanks!

For your reference, I am using android studio and genymotion. The app API is 23.

2 Answers2

4

The app has not been approve for the permission to write to the external memory, this is a new feature for android 23 Marshmallow called Run time permission.

You first need to create a runtime permission for user to accept and approve to write to the external memory before you can write to it.

Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63
0

You can try this.

 Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);

to

 Bitmap bitmap = BitmapFactory.decodeFile("file://"+mCurrentPhotoPath);

I hope this will help you. thanks

rockstar
  • 587
  • 4
  • 22
  • After applying @Rod_Algonquin answer, I tried your suggestion by curiosity. Turns out it results in a "ENOENT (No such file or directory) error. – Michaël Polla Jul 19 '16 at 16:30