Skip to content

[image_picker] Fix android-16 not picking up file - #11320

Merged
auto-submit[bot] merged 37 commits into
flutter:mainfrom
ashutosh2014:image-picker-Fix-android-16-not-picking-up-file
Sep 3, 2026
Merged

auto-submit[bot] merged 37 commits into
flutter:mainfrom
ashutosh2014:image-picker-Fix-android-16-not-picking-up-file

Conversation

@ashutosh2014

@ashutosh2014 ashutosh2014 commented Mar 21, 2026 •

Copy link
Copy Markdown
Contributor

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

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-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.

Footnotes

  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. ↩ ↩2

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

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.

@stuartmorgan-g
stuartmorgan-g marked this pull request as draft March 22, 2026 16:39
@ashutosh2014

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g

flutter/flutter#182071

This is the issue fixed by this current PR

@ashutosh2014
ashutosh2014 marked this pull request as ready for review March 22, 2026 16:46

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +3 to +5
* 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
* 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The reference to "Android 16 (API 36)" is potentially confusing. To improve clarity, it would be better to refer to the API level directly.

Suggested change
* <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

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

@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
stuartmorgan-g marked this pull request as draft March 22, 2026 16:58
@ashutosh2014

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g Updated PR description with full details, tests, and issue link. Ready for review.

@ashutosh2014
ashutosh2014 marked this pull request as ready for review March 22, 2026 17:54

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 gmackall added the CICD Run CI/CD label Mar 26, 2026

@gmackall gmackall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@ashutosh2014

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g Thanks for comments, Can you check now?

@@ -1,3 +1,7 @@
## NEXT

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Which of the documented versioning exemptions (per the link in the checklist) do you believe this PR falls under?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Versioning Fixed.

@stuartmorgan-g stuartmorgan-g added the CICD Run CI/CD label Aug 27, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 27, 2026
@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

@ashutosh2014 Every time you push a new commit to this PR, it requires human intervention to re-add the CICD label, and then all the tests have to run again, making it take longer to land. Please don't just push merges for no reason.

@stuartmorgan-g stuartmorgan-g added the CICD Run CI/CD label Aug 27, 2026
@tarrinneal

Copy link
Copy Markdown
Contributor

These files are not formatted correctly (see diff below):
packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java

To fix run the repository tooling format command: https://github.com/flutter/packages/blob/main/script/tool/README.md#format-code
or copy-paste this command into your terminal:
patch -p1 <<DONE
diff --git a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java
index 438f1860da..ce61b61fad 100644
--- a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java
+++ b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java
@@ -94,8 +94,8 @@ final class ImagePickerUtils {
* androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia} (Android Photo
* Picker) instead of {@link android.content.Intent#ACTION_GET_CONTENT}.
*

    • On Android API 36+, {@code ACTION_GET_CONTENT} for images may be handled by the system

    • photo picker's {@code PhotopickerGetContentActivity}. That path combined with {@code
    • On Android API 36+, {@code ACTION_GET_CONTENT} for images may be handled by the system photo

    • picker's {@code PhotopickerGetContentActivity}. That path combined with {@code
    • startActivityForResult} can return {@link android.app.Activity#RESULT_OK} without {@link
    • android.content.Intent#getData()} or usable {@link android.content.ClipData}, so the plugin
    • would complete with no paths. The {@code PickVisualMedia} contract uses the Activity Result API

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 28, 2026
@ashutosh2014

Copy link
Copy Markdown
Contributor Author

These files are not formatted correctly (see diff below): packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java

To fix run the repository tooling format command: https://github.com/flutter/packages/blob/main/script/tool/README.md#format-code or copy-paste this command into your terminal: patch -p1 <<DONE diff --git a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java index 438f1860da..ce61b61fad 100644 --- a/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java +++ b/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerUtils.java @@ -94,8 +94,8 @@ final class ImagePickerUtils { * androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia} (Android Photo * Picker) instead of {@link android.content.Intent#ACTION_GET_CONTENT}. *

    • On Android API 36+, {@code ACTION_GET_CONTENT} for images may be handled by the system
    • photo picker's {@code PhotopickerGetContentActivity}. That path combined with {@code
    • On Android API 36+, {@code ACTION_GET_CONTENT} for images may be handled by the system photo
    • picker's {@code PhotopickerGetContentActivity}. That path combined with {@code
    • startActivityForResult} can return {@link android.app.Activity#RESULT_OK} without {@link
    • android.content.Intent#getData()} or usable {@link android.content.ClipData}, so the plugin
    • would complete with no paths. The {@code PickVisualMedia} contract uses the Activity Result API

Done

@stuartmorgan-g stuartmorgan-g added the CICD Run CI/CD label Aug 28, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Sep 1, 2026
@stuartmorgan-g stuartmorgan-g added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Sep 1, 2026
@auto-submit
auto-submit Bot merged commit f9b3954 into flutter:main Sep 3, 2026
14 checks passed
github-merge-queue Bot pushed a commit to flutter/flutter that referenced this pull request Sep 3, 2026
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
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
## 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.
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: image_picker platform-android

Projects

None yet

5 participants