Expected Visual Media type got imageOnly

I want to add a photo picker in my Android App, for which i got folllowing snippet from Android docs. (PhotoPicker)

ActivityResultLauncher<PickVisualMediaRequest> pickMultipleMedia =
    registerForActivityResult(new PickMultipleVisualMedia(5), uris -> {
// Callback is invoked after the user selects media items or closes the
// photo picker.
if (!uris.isEmpty()) {
    Log.d("PhotoPicker", "Number of items selected: " + uris.size());
} else {
    Log.d("PhotoPicker", "No media selected");
pickMultipleMedia.launch(new PickVisualMediaRequest.Builder()

But i am getting an error:

'setMediaType(androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia.VisualMediaType)' in 'androidx.activity.result.PickVisualMediaRequest.Builder' cannot be applied to '(androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia.ImageOnly)'

Though there is this error, the app is running well. I am not able to fix the issue


  • androidx.activity:activity:1.7.0 update to this dependency they fixed the issue