image-chooser-library icon indicating copy to clipboard operation
image-chooser-library copied to clipboard

Android M - ImageChooserManager.choose() error creating directory

Open robgravy opened this issue 9 years ago • 13 comments

I am using the 1.5.0 version of this library testing my app on the Android M Preview Release 3.

mChooseType = ChooserType.REQUEST_PICK_PICTURE;
                    mImageChooserManager = new ImageChooserManager(mActivity, mChooseType, true);
                    mImageChooserManager.setImageChooserListener(imageChosenListener);
                    try {
                        filePath = mImageChooserManager.choose();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

I get the following error when it attempts to call choose():

Error creating directory: /storage/emulated/0/bichooser
 at com.kbeanie.imagechooser.api.BChooser.checkDirectory(BChooser.java:149)
 at com.kbeanie.imagechooser.api.ImageChooserManager.choosePicture(ImageChooserManager.java:222)
 at com.kbeanie.imagechooser.api.ImageChooserManager.choose(ImageChooserManager.java:209)

robgravy avatar Sep 30 '15 16:09 robgravy

Do you have read/write external storage permissions?

coomar2841 avatar Sep 30 '15 16:09 coomar2841

Yes

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

robgravy avatar Sep 30 '15 16:09 robgravy

Can you post some more logs?

coomar2841 avatar Sep 30 '15 17:09 coomar2841

When I use 1.4.4 version of this lib a Toast pops up and here are the logs:

java.io.FileNotFoundException: /storage/emulated/0/bimagechooser/1443635066334.jpg: open failed: ENOENT (No such file or directory)
 at libcore.io.IoBridge.open(IoBridge.java:452)
 at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
 at java.io.FileOutputStream.<init>(FileOutputStream.java:127)
 at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
 at com.kbeanie.imagechooser.threads.MediaProcessorThread.processGooglePhotosMedia(MediaProcessorThread.java:401)
 at com.kbeanie.imagechooser.threads.ImageProcessorThread.processImage(ImageProcessorThread.java:94)
 at com.kbeanie.imagechooser.threads.ImageProcessorThread.run(ImageProcessorThread.java:53)
 Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
 at libcore.io.Posix.open(Native Method)
 at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
 at libcore.io.IoBridge.open(IoBridge.java:438)
 ... 6 more
 java.io.FileNotFoundException: /storage/emulated/0/bimagechooser/1443635066334.jpg: open failed: ENOENT (No such file or directory)
 at libcore.io.IoBridge.open(IoBridge.java:452)
 at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
 at java.io.FileOutputStream.<init>(FileOutputStream.java:127)
 at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
 at com.kbeanie.imagechooser.threads.MediaProcessorThread.processGooglePhotosMedia(MediaProcessorThread.java:401)
 at com.kbeanie.imagechooser.threads.ImageProcessorThread.processImage(ImageProcessorThread.java:94)
 at com.kbeanie.imagechooser.threads.ImageProcessorThread.run(ImageProcessorThread.java:53)
 Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
 at libcore.io.Posix.open(Native Method)
 at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
 at libcore.io.IoBridge.open(IoBridge.java:438)

robgravy avatar Sep 30 '15 17:09 robgravy

Looks like the new permissions issue with M. Will check it out.

Thanks and Regards,Kumar Bibek

http://techdroid.kbeanie.com http://techdroid.kbeanie.comhttp://www.kbeanie.com http://www.kbeanie.com

On Wed, Sep 30, 2015 at 11:16 PM, Rob Gray [email protected] wrote:

When I use 1.4.4 version of this lib a Toast pops up and here are the logs:

java.io.FileNotFoundException: /storage/emulated/0/bimagechooser/1443635066334.jpg: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:452) at java.io.FileOutputStream.(FileOutputStream.java:87) at java.io.FileOutputStream.(FileOutputStream.java:127) at java.io.FileOutputStream.(FileOutputStream.java:116) at com.kbeanie.imagechooser.threads.MediaProcessorThread.processGooglePhotosMedia(MediaProcessorThread.java:401) at com.kbeanie.imagechooser.threads.ImageProcessorThread.processImage(ImageProcessorThread.java:94) at com.kbeanie.imagechooser.threads.ImageProcessorThread.run(ImageProcessorThread.java:53) Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:438) ... 6 more java.io.FileNotFoundException: /storage/emulated/0/bimagechooser/1443635066334.jpg: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:452) at java.io.FileOutputStream.(FileOutputStream.java:87) at java.io.FileOutputStream.(FileOutputStream.java:127) at java.io.FileOutputStream.(FileOutputStream.java:116) at com.kbeanie.imagechooser.threads.MediaProcessorThread.processGooglePhotosMedia(MediaProcessorThread.java:401) at com.kbeanie.imagechooser.threads.ImageProcessorThread.processImage(ImageProcessorThread.java:94) at com.kbeanie.imagechooser.threads.ImageProcessorThread.run(ImageProcessorThread.java:53) Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:438)

— Reply to this email directly or view it on GitHub https://github.com/coomar2841/image-chooser-library/issues/114#issuecomment-144488462 .

coomar2841 avatar Sep 30 '15 17:09 coomar2841

I found the issue, in API >= 23 you have to check for Read/Write external storage permissions even if its listed in your manifest.

    private static final int REQUEST_EXTERNAL_STORAGE = 1;
    private static String[] PERMISSIONS_STORAGE = {Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE};

            ActivityCompat.requestPermissions(mActivity, PERMISSIONS_STORAGE,
                     REQUEST_EXTERNAL_STORAGE);

This will prompt for access. This resolved the error.

robgravy avatar Sep 30 '15 20:09 robgravy

Thanks. Will try to do include this permission flow in the library itself for the next release.

coomar2841 avatar Oct 03 '15 10:10 coomar2841

my think... need not permission WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE use getExternalFilesDir or getExternalCacheDir

parkjaeiek avatar Oct 14 '15 05:10 parkjaeiek

Hey, are you planning to implement Android Runtime Permissions with external storage? Or maybe optional to save in externalFilesDir / externalCacheDir as @parkjaeiek said. It would be even nicer approach.

yayaa avatar Feb 19 '16 13:02 yayaa

Yes. Will be implementing both.

coomar2841 avatar Feb 19 '16 14:02 coomar2841

Hi, When can we expect to get a new version with this issue fixed?

SriKrishnaCovalense avatar Mar 17 '16 13:03 SriKrishnaCovalense

I haven't found a way to prompt for runtime permissions form the library itself.

As for the locations, I am working on it.

In the meantime, you might want to switch to this new library. It might be a bit of work, but I have re-written this library to make it easier to handle future enhancements.

https://github.com/coomar2841/android-multipicker-library

coomar2841 avatar Mar 17 '16 18:03 coomar2841

Thanks :) I will look into it and Switch into it soon.

SriKrishnaCovalense avatar Mar 18 '16 05:03 SriKrishnaCovalense