coomar2841 / image-chooser-library

An Easy Image/Video Chooser Library for your Android Apps
646 stars 193 forks source link

Android M - ImageChooserManager.choose() error creating directory #114

Closed robgravy closed 2 months ago

robgravy commented 8 years ago

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)
coomar2841 commented 8 years ago

Do you have read/write external storage permissions?

robgravy commented 8 years ago

Yes

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
coomar2841 commented 8 years ago

Can you post some more logs?

robgravy commented 8 years ago

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)
coomar2841 commented 8 years ago

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 notifications@github.com 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 .

robgravy commented 8 years ago

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.

coomar2841 commented 8 years ago

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

parkjaeiek commented 8 years ago

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

yayaa commented 8 years ago

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.

coomar2841 commented 8 years ago

Yes. Will be implementing both.

SriKrishnaCovalense commented 8 years ago

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

coomar2841 commented 8 years ago

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

SriKrishnaCovalense commented 8 years ago

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