1

The image_picker, has the following three methods to reference when wanting to make device XFile selections:

  • pickImage()
  • pickVideo()
  • pickMultiImage()
  • pickMultiMedia() <- this is the one i want

From their own documentation:

On Android 13 and above this package uses the Android Photo Picker . On Android 12 and below use of Android Photo Picker is optional. Learn how to use it.

But unless you're on iOS, the pickMultiMedia opens the Android file system that accepts a variety of file formats (e.g. pdf, ico). And instead of opening the device gallery like it does with iOS, it opens androids file system. I put together this quick android app that demonstrates how to use the Android Photo Picker. And for whatever reason, the image_picker package doesn't use this for its android support and i want to know why. Or is there something im doing wrong. I also have no clue how to contribute to Flutter's package repositories.

import androidx.activity.result.contract.ActivityResultContracts.PickMultipleVisualMedia

class MainActivity : ComponentActivity() {
 private val pickMediaLauncher = registerForActivityResult(PickMultipleVisualMedia()) {}
 
 override fun onCreate(savedInstanceState: Bundle?) {
  ...

  pickButton.setOnClickListener {
   val request = PickVisualMediaRequest.Builder()
    .setMediaType(ActivityResultContracts.PickVisualMedia.ImageAndVideo)
     .build()

   pickMediaLauncher.launch(request)
  }
 }
}

1 Answer 1

0

The image_picker package needs two additional packages, image_picker_android and image_picker_platform_interface. Then you can continue using ImagePicker().pickMultiMedia() on both Android and iOS.

setup the main.dart file:

void main() {
 final ImagePickerPlatform implementation = ImagePickerPlatform.instance;
 if (implementation is ImagePickerAndroid) {
  implementation.useAndroidPhotoPicker = true;
 }
 
 ...
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.