Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ClassCastException ( MediaPickerFragment cannot be cast to ImagePickerFragment) #72

Open
umesh0492 opened this issue Nov 6, 2023 · 3 comments · Fixed by #76
Labels
bug Something isn't working
Milestone

Comments

@umesh0492
Copy link

coroutineScope.launch {
                            //var image: ImageBitmap? by remember { mutableStateOf(null) }
                            val result = picker.pickImage(MediaSource.CAMERA)
                            try {
                                result.toImageBitmap()
                            } catch (e: Exception) {

                            }
                        }
java.lang.ClassCastException: dev.icerock.moko.media.picker.MediaPickerFragment cannot be cast to dev.icerock.moko.media.picker.ImagePickerFragment
                                                                                                    	at dev.icerock.moko.media.picker.MediaPickerControllerImpl.pickImage(MediaPickerControllerImpl.kt:62)
                                                                                                    	at dev.icerock.moko.media.picker.MediaPickerControllerImpl.pickImage(MediaPickerControllerImpl.kt:44)
@umesh0492 umesh0492 changed the title java.lang.ClassCastException java.lang.ClassCastException ( MediaPickerFragment cannot be cast to ImagePickerFragment) Nov 6, 2023
@umesh0492
Copy link
Author

With
dev.icerock.moko:media:0.11.0
dev.icerock.moko:media-compose:0.11.0

@davgdafa
Copy link

davgdafa commented Nov 20, 2023

I think you need to add all permissions for all versions in the AndroidManifest of the Android app as in here:


    <!-- Devices running Android 12L (API level 32) or lower  -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />

    <!-- Devices running Android 13 (API level 33) or higher -->
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"  />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

    <!-- To handle the reselection within the app on Android 14 (API level 34) -->
    <uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />

That worked for me.

@anton-veretenenko
Copy link

got that exception too, code to reproduce

picker.pickImage(MediaSource.CAMERA)
picker.pickMedia()

so exception happens when you try to use several pickers from the same composable, because pickerFragmentTag is always the same

@Alex009 Alex009 added this to the 0.11.1 milestone Mar 24, 2024
@Alex009 Alex009 added the bug Something isn't working label Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants