javaandroidkotlingoogle-playgoogle-play-services

Google play Something went wrong error on pick a media from gallery


in some devices (especially in android 14) when i want to pick a media from gallery using PickVisualMediaRequest google play shows Something went wrong and i can't do anything.

This is the error: click to view error image

Here is my code to pick media:

ActivityResultLauncher<PickVisualMediaRequest> pickMedia =
            registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), new ActivityResultCallback<Uri>() {
                @Override
                public void onActivityResult(Uri uri) {
                    if (uri != null) {
                        // my stuff
                    }
                }
            });
pickMedia.launch(new PickVisualMediaRequest.Builder()
        .setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
        .build());

NOTE: I use a single signature key in 3 of my apps.

I searched on Google, but I did not find any solution to my problem. also i tested on emulator with android 14 but it worked fine for me.


Solution

  • I had the same problem and I got it fixed by updating the google play services app on the phone, but since I was looking for an alternative solution that doesn't require the user to update their play servies, I found out that PickVisualMedia is the newer API which might not work seamlessly on all versions of android with different play servies (not sure why!?) but using the old api saved my day.

    val launcher = rememberLauncherForActivityResult(
        contract = ActivityResultContracts.GetContent(),
        onResult = { uri ->
            uri?.let { viewModel.addCover(cover = uri) }
        }
    )
    launcher.launch("image/*")