Kotlin ImagePicker Solution After Version Update

91 Views Asked by At

I used in my project this ImagePicker Library.

https://github.com/Dhaval2404/ImagePicker

I used it this way in the old version, but this "getFile" function has been removed in the new version. I have to use the new version because of the "WRITE_EXTERNAL_STORAGE" permission error in Android 13.

.getFile removed in v2.0

https://github.com/Dhaval2404/ImagePicker/pull/200/files#diff-a18addafe8b8ac956554293f48d74cf38a8b260efcef49b8c25a6b3965d11038

Code :

private fun addPhoto() {
       requireActivity().showImagePicker {
           if (it.resultCode == Activity.RESULT_OK && it.data != null) {
               val result = it.data.data
               if (result != null) {
                   val imageFile: File = ImagePicker.getFile(it.data)!!
                   listPhotos = ArrayList()
                   listPhotos.add(imageFile)
                   savePhoto()
               }
           } else if (it.resultCode == ImagePicker.RESULT_ERROR) {
               toastError(ImagePicker.getError(it.data))
           }
       }
   }
0

There are 0 best solutions below