简体   繁体   中英

Permission denied when creating bitmap from photo path

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.

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.

You can try this.

 Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);

to

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

I hope this will help you. thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM