Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.13+6

* Fixes an Android issue where `pickMedia` allowed non-image files to be selected.

## 0.8.13+5

* Updates Java compatibility version to 17 and minimum supported SDK version to Flutter 3.35/Dart 3.9.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private void launchPickMediaFromGalleryIntent(Messages.GeneralOptions generalOpt
pickMediaIntent = new Intent(Intent.ACTION_GET_CONTENT);
pickMediaIntent.setType("*/*");
String[] mimeTypes = {"video/*", "image/*"};
pickMediaIntent.putExtra("CONTENT_TYPE", mimeTypes);
pickMediaIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change correctly fixes the issue by using the standard Intent.EXTRA_MIME_TYPES.

To ensure this functionality is covered against future regressions, please consider adding a unit test.1 A test could verify that when usePhotoPicker is false, the launched Intent has the correct action, type, and EXTRA_MIME_TYPES set.

Here is an example of what such a test could look like in ImagePickerDelegateTest.java:

@Test
@Config(sdk = 30) // To test the 'else' branch for non-photo-picker
public void chooseMediaFromGallery_launchesIntentWithCorrectMimeTypes() {
    ImagePickerDelegate delegate = createDelegate();
    GeneralOptions generalOptions =
        new GeneralOptions.Builder().setAllowMultiple(false).setUsePhotoPicker(false).build();
    delegate.chooseMediaFromGallery(DEFAULT_MEDIA_OPTIONS, generalOptions, mockResult);

    ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
    verify(mockActivity)
        .startActivityForResult(
            intentCaptor.capture(), eq(ImagePickerDelegate.REQUEST_CODE_CHOOSE_MEDIA_FROM_GALLERY));
    
    Intent intent = intentCaptor.getValue();
    assertEquals(Intent.ACTION_GET_CONTENT, intent.getAction());
    assertEquals("*/*", intent.getType());
    String[] mimeTypes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES);
    assertArrayEquals(new String[]{"video/*", "image/*"}, mimeTypes);
}

Style Guide References

Footnotes

  1. The repository style guide states that code should be tested, and changes to plugin packages should have appropriate tests. (link)

pickMediaIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, generalOptions.getAllowMultiple());
}
activity.startActivityForResult(pickMediaIntent, REQUEST_CODE_CHOOSE_MEDIA_FROM_GALLERY);
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: image_picker_android
description: Android implementation of the image_picker plugin.
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.13+5
version: 0.8.13+6

environment:
sdk: ^3.9.0
Expand Down