coomar2841 / android-multipicker-library

Android Multipicker Library
Apache License 2.0
438 stars 107 forks source link

Possible fix for #146 #172

Closed dabarnard closed 4 years ago

dabarnard commented 4 years ago

Hi @coomar2841 ,

I have been using your library for a while. Ran into some issues when image picking on newer devices (specifically modern Samsung and Huawei devices).

It sounds similar to what was described in issue #146

I forked your library and managed to resolve the issue for my project at least. I have created a PR for your reference in case you can use it for a future release.

One last note is that the only other change I needed to make was to ensure the data persisted after restarts. I did this by modifying the section in onActivityResult as follows:

if (requestCode == Picker.PICK_IMAGE_DEVICE) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        val takeFlags = data!!.getFlags() and Intent.FLAG_GRANT_READ_URI_PERMISSION
        val resolver = activity!!.contentResolver 
        resolver.takePersistableUriPermission(data.data, takeFlags)  //data  is the passed in intent
     }
     imagePicker.submit(data)
}

Please note my use case was just for single image selection, and overall might need some additional null checking. Hope this is useful to you/your users.

All the best and thanks for sharing your library with us.

-Dieter