Repository navigation
[image_picker] Fix android-16 not picking up file - #11320
auto-submit[bot] merged 37 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request addresses an issue on Android 16 (API 36) where the image picker would not return a file path. The solution is to enforce the use of the Android Photo Picker on API 36 and higher, which is implemented via a new utility method, effectiveUsePhotoPicker. This logic is consistently applied throughout the ImagePickerDelegate. The change is also accompanied by new unit tests, which is great. My review includes a minor suggestion to simplify the logic in the new utility method for improved conciseness.
Thanks for the contribution! You’ve checked boxes in the PR checklist above that are not reflected in this PR, so I’m assuming this is a work in progress and am marking it as a Draft. Please review the checklist, updating the PR as appropriate, and when the state of the PR as posted reflects the checklist please feel free to mark it as ready for review. |
|
This is the issue fixed by this current PR |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue with file selection on Android API 36+ by enforcing the use of the Android Photo Picker. The implementation introduces a new utility method and is accompanied by corresponding tests, which is great. My feedback focuses on improving the clarity of a new constant and associated comments to prevent potential confusion regarding Android versions and API levels.
| * Fixes gallery image/video selection on Android 16 (API 36) returning no paths when | ||
| `useAndroidPhotoPicker` was false. The plugin now uses the Android Photo Picker on API 36 and | ||
| above regardless of that flag, avoiding a broken `ACTION_GET_CONTENT` result from the system UI. |
There was a problem hiding this comment.
The reference to "Android 16 (API 36)" could be confusing, as Android version 16 doesn't correspond to API level 36. To improve clarity, consider referring to the API level directly.
| * Fixes gallery image/video selection on Android 16 (API 36) returning no paths when | |
| `useAndroidPhotoPicker` was false. The plugin now uses the Android Photo Picker on API 36 and | |
| above regardless of that flag, avoiding a broken `ACTION_GET_CONTENT` result from the system UI. | |
| * Fixes gallery image/video selection on Android API 36+ returning no paths when | |
| `useAndroidPhotoPicker` was false. The plugin now uses the Android Photo Picker on API 36 and | |
| above regardless of that flag, avoiding a broken `ACTION_GET_CONTENT` result from the system UI. |
| import java.util.Arrays; | ||
|
|
||
| final class ImagePickerUtils { | ||
| private static final int ANDROID_16_API_LEVEL = 36; |
There was a problem hiding this comment.
The constant name ANDROID_16_API_LEVEL is potentially misleading, as Android version 16 corresponds to API level 23 (Jelly Bean), not 36. A more generic name like API_LEVEL_36 would be clearer and avoid confusion. Please also update its usage within this file.
| private static final int ANDROID_16_API_LEVEL = 36; | |
| private static final int API_LEVEL_36 = 36; |
| * androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia} (Android Photo | ||
| * Picker) instead of {@link android.content.Intent#ACTION_GET_CONTENT}. | ||
| * | ||
| * <p>On Android 16 (API 36), {@code ACTION_GET_CONTENT} for images may be handled by the system |
There was a problem hiding this comment.
The reference to "Android 16 (API 36)" is potentially confusing. To improve clarity, it would be better to refer to the API level directly.
| * <p>On Android 16 (API 36), {@code ACTION_GET_CONTENT} for images may be handled by the system | |
| * <p>On Android API 36+, {@code ACTION_GET_CONTENT} for images may be handled by the system |
|
@ashutosh2014 Please edit the PR description to include that information, along with the other requested information, instead of leaving placeholder text there and putting the requested information only in the comments. |
|
@stuartmorgan-g Updated PR description with full details, tests, and issue link. Ready for review. |
There was a problem hiding this comment.
Code Review
This pull request addresses an issue with file picking on Android API 36+ by conditionally forcing the use of the Android Photo Picker. A new method, effectiveUsePhotoPicker, is introduced in ImagePickerUtils.java to encapsulate this logic, which is now used throughout ImagePickerDelegate.java. The change also includes unit tests for the new logic and updates the package's changelog and version.
gmackall
left a comment
There was a problem hiding this comment.
LGTM but it would be good to also update the docs for useAndroidPhotoPicker
to indicate it is not respected on android 16+
cc @tarrinneal for secondary review
…droid-16-not-picking-up-file
…ps://github.com/ashutosh2014/packages into image-picker-Fix-android-16-not-picking-up-file
|
@stuartmorgan-g Thanks for comments, Can you check now? |
| @@ -1,3 +1,7 @@ | |||
| ## NEXT | |||
There was a problem hiding this comment.
Which of the documented versioning exemptions (per the link in the checklist) do you believe this PR falls under?
There was a problem hiding this comment.
Versioning Fixed.
|
@ashutosh2014 Every time you push a new commit to this PR, it requires human intervention to re-add the |
|
These files are not formatted correctly (see diff below): To fix run the repository tooling
|
Done |
flutter/packages@18fe786...f9b3954 2026-09-03 [email protected] [image_picker] Fix android-16 not picking up file (flutter/packages#11320) 2026-09-02 [email protected] [material_ui] Migrate off of flutter_test's find.byTooltip and on to the local findByTooltip (flutter/packages#12492) 2026-09-02 [email protected] [material_ui] Remove no shuffle from text field tests (flutter/packages#12547) 2026-09-02 [email protected] Add Material style variant enum (#12221) (flutter/packages#12717) 2026-09-02 [email protected] [go_router_builder] Report duplicate route paths at build time (flutter/packages#12399) 2026-09-02 [email protected] [google_sign_in] PR 1/4 google_sign_in_ios SPM packaging (flutter/packages#12654) 2026-09-02 [email protected] [video_player_android] Report display size for anamorphic video (flutter/packages#12360) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
## Description Fixes an issue where `image_picker` returns a null file after selecting an image from the gallery on Android 16+, caused by incorrect handling of content URIs in the Android implementation. ## Changes - Updated `ImagePickerUtils.java` to handle Android 16+ behavior correctly - Fixed file picking logic ## Tests - Added unit tests for `effectiveUsePhotoPicker` to verify behavior on Android 16 (API 36) - Ensured correct behavior across API levels ## Issue Fixes flutter/flutter#182071 Fixes flutter/flutter#184826 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
## Description Fixes an issue where `image_picker` returns a null file after selecting an image from the gallery on Android 16+, caused by incorrect handling of content URIs in the Android implementation. ## Changes - Updated `ImagePickerUtils.java` to handle Android 16+ behavior correctly - Fixed file picking logic ## Tests - Added unit tests for `effectiveUsePhotoPicker` to verify behavior on Android 16 (API 36) - Ensured correct behavior across API levels ## Issue Fixes flutter/flutter#182071 Fixes flutter/flutter#184826 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Description
Fixes an issue where
image_pickerreturns a null file after selecting an image from the gallery on Android 16+, caused by incorrect handling of content URIs in the Android implementation.Changes
ImagePickerUtils.javato handle Android 16+ behavior correctlyTests
effectiveUsePhotoPickerto verify behavior on Android 16 (API 36)Issue
Fixes flutter/flutter#182071
Fixes flutter/flutter#184826
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2