nguyenhoanglam / ImagePicker

A customizable library for selecting images on the device.
Apache License 2.0
599 stars 156 forks source link

Android 11 : Crash when capturing a photo from ImagePicker #134

Closed Pocus76 closed 2 years ago

Pocus76 commented 3 years ago

My Android S10+ running Android 11 is crashing when I try to capture a photo using the camera from the ImagePicker, otherwise it's working fine on a XCover 4S running Android 10.

I'm having the following stacktrace with Android 11 :

FATAL EXCEPTION: android.bg
java.lang.IllegalStateException: uri must not be null
    at com.nguyenhoanglam.imagepicker.ui.camera.DefaultCameraModule$getImage$2.onScanCompleted(DefaultCameraModule.kt:96)
    at android.media.MediaScannerConnection.runCallBack(MediaScannerConnection.java:277)
    at android.media.MediaScannerConnection.lambda$scanFile$2(MediaScannerConnection.java:254)
    at android.media.-$$Lambda$MediaScannerConnection$OHvRCUP9iHmcrBgJ56umGlJZPUU.run(Unknown Source:6)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:246)
    at android.os.HandlerThread.run(HandlerThread.java:67)

When capturing a photo with Android 10, the following Exception appears in the logs ut the photo get captured anyway and appears in the ImagePicker

W/Binder: Caught a RuntimeException from the binder stub implementation.
    java.lang.IllegalStateException: uri must not be null
        at com.nguyenhoanglam.imagepicker.ui.camera.DefaultCameraModule$getImage$2.onScanCompleted(DefaultCameraModule.kt:96)
        at android.media.MediaScannerConnection$ClientProxy.onScanCompleted(MediaScannerConnection.java:254)
        at android.media.MediaScannerConnection$1.scanCompleted(MediaScannerConnection.java:55)
        at android.media.IMediaScannerListener$Stub.onTransact(IMediaScannerListener.java:97)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)

I'm using the latest version of the ImagePicker (1.4.3) and I'm trying to save the picture with : setDirectoryName(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES+"/camera/")

Am I doing something wrong ?

Any help would be appreciated

dgecek commented 3 years ago

You are setting the wrong directory name. From android 11 upwards you should use getExternalFilesDir(Environment.DIRECTORY_PICTURES): https://developer.android.com/about/versions/11/privacy/storage

Pocus76 commented 3 years ago

You are setting the wrong directory name. From android 11 upwards you should use getExternalFilesDir(Environment.DIRECTORY_PICTURES): https://developer.android.com/about/versions/11/privacy/storage

Thanks for your answer Unfortunately, after setting this value it keeps crashing with the same error

nguyenhoanglam commented 2 years ago

@Pocus76 version 1.5.0 is available. please check it out!

Pocus76 commented 2 years ago

This issue was fixed in the latest version of the library, 1.5.1, huge thanks @nguyenhoanglam