EasyImage icon indicating copy to clipboard operation
EasyImage copied to clipboard

Images taken from camera do not call onMediaFilesPicked if camera was selected from chooser

Open waltermaldonado opened this issue 5 years ago • 8 comments

I think this is a bug, the method onMediaFilesPicked will be called only if you take a picture from openCameraForImage. If you pick Camera from openChooser the method is skipped.

Error message: D/EasyImage: File returned from chooser Existing picture returned from local storage W/System.err: kotlin.KotlinNullPointerException at pl.aprilapps.easyphotopicker.EasyImage.onPickedExistingPicturesFromLocalStorage(EasyImage.kt:171) at pl.aprilapps.easyphotopicker.EasyImage.onPickedExistingPictures(EasyImage.kt:201) W/System.err: at pl.aprilapps.easyphotopicker.EasyImage.onFileReturnedFromChooser(EasyImage.kt:249) at pl.aprilapps.easyphotopicker.EasyImage.handleActivityResult(EasyImage.kt:156)

waltermaldonado avatar Sep 17 '19 19:09 waltermaldonado

Same here with Android 10

maresdeka avatar Oct 04 '19 08:10 maresdeka

exact same problem on emulator android 8.0.0 (api 26)

htchaan avatar Nov 04 '19 16:11 htchaan

same problem on android 10

jubeiargh avatar Nov 05 '19 23:11 jubeiargh

The problem still exists. Any idea?

onurgunes avatar Dec 05 '19 06:12 onurgunes

I was able to mitigate it with the following

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        activity?.let {
            val dataIntent = fixDataIntentForEasyImage(data)
            easyImage.handleActivityResult(requestCode, resultCode, dataIntent, it, callback)
            ...
       }
}

private fun fixDataIntentForEasyImage(dataIntent: Intent?): Intent? {
        if (dataIntent == null) {
            return null
        }
        if (dataIntent.dataString.isNullOrEmpty()) {
            return null
        }

        return dataIntent
    }

The issue comes from the fact that EasyImage relies on the fact that the result data intent is null if the image came from the camera. This is not true for all cameras though. Some return an Intent without data.

peshkira avatar Dec 14 '19 16:12 peshkira

The same issue here. Should I fallback to 2.x?

ionull avatar Feb 17 '20 07:02 ionull

falling back does not work for me :c

o-nos avatar Oct 12 '21 08:10 o-nos

Still, this issue occurred with android version 10 (Redmi devices). Please check and fix this issue. Currently, I have used dependency "implementation 'com.github.jkwiecien:EasyImage:3.2.0'".

Functionality used by me.

val dataIntent = fixDataIntentForEasyImage(data)

        easyImage.handleActivityResult(
            requestCode,
            resultCode,
            dataIntent,
            mContext as AppCompatActivity,
            object : DefaultCallback() {

                override fun onMediaFilesPicked(
                    imageFiles: Array<MediaFile>,
                    source: MediaSource
                ) {

                    Log.e("imageFiles", "" + imageFiles.size)

                    CropImage.activity(Uri.fromFile(imageFiles[0].file))
                        .setAllowFlipping(false)
                        .start(mContext as AppCompatActivity)
                }
            })

====================================

private fun fixDataIntentForEasyImage(dataIntent: Intent?): Intent? { if (dataIntent == null) { return null } if (dataIntent.dataString.isNullOrEmpty()) { return null } return dataIntent }

Dhiraj-kumar-kumawat avatar Dec 16 '21 09:12 Dhiraj-kumar-kumawat