ChiliLabs / ChiliPhotoPicker

Photo picker library for android. Let's you pick photos directly from files, or navigate to camera or gallery.
Apache License 2.0
405 stars 45 forks source link

onImagesPicked callback is not called in fragment #18

Closed theanilpaudel closed 4 years ago

theanilpaudel commented 4 years ago

I have written the code like below

fun showPhotoPickerFragment() {
        PhotoPickerFragment.newInstance(
            multiple = false,
            allowCamera = true,
            theme = R.style.ChiliPhotoPicker_Light
        ).show(requireActivity().supportFragmentManager, "UploadProfileFragment")
    }
override fun onImagesPicked(photos: ArrayList<Uri>) {
    val initialPath = photos.get(0).path
    if (initialPath?.contains("emulated")!!) {
        imagePath = initialPath
    } else {
        imagePath = "/data/data/${requireActivity().packageName}/cache" + initialPath
    }
    println("onImagesPicked $imagePath")
    val file = File(imagePath)
    Picasso.with(requireContext()).load(file).into(binding.ivProfilePic)
}

In the Application class, I am initializing like this ChiliPhotoPicker.init(loader = PicassoImageLoader(), authority = "$packageName.fileprovider")

When I run the code, the Picker appears but when I select a image the onImagePicked callback is never called.

theanilpaudel commented 4 years ago

Stupid mistake,

I added childFragmentManager instead of requireActivity().supportFragmentManager and it is working fine.