Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

hubatruck
Copy link
Contributor

@hubatruck hubatruck commented Jun 7, 2024

Thanks for submitting a PR! Please read these instructions carefully:

  • Explain the motivation for making this change.
  • Provide a test plan demonstrating that the code is solid.
  • Match the code formatting of the rest of the codebase.
  • Target the main branch, NOT a "stable" branch.

Motivation (required)

What existing problem does the pull request solve?

For a more privacy preserving experience for users, we’re introducing the Photo and Video Permissions policy to reduce the number of apps permitted to request broad photo/video permissions (READ_MEDIA_IMAGES and READ_MEDIA_VIDEO). Apps may only access photos and videos for purposes directly related to app functionality. Apps that have a one-time or infrequent need to access these files are requested to use a system picker, such as the Android photo picker. (effective August 31, 2024)

Reference: https://support.google.com/googleplay/android-developer/answer/13986130

Converted the launchImageLibrary Android function to use the native AndroidX Photo Picker: https://developer.android.com/training/data-storage/shared/photopicker

Test Plan (required)

Tested out on multiple devices, both with the example app, and on my own project.

  • Tried selecting single image
  • Tried selecting multiple images
  • Tried selecting single video
  • Tried selecting multiple videos
  • Tried selecting single video/image
  • Tried selecting multiple videos/images

Devices used:

Make Android version
Samsung SM-A520F Android 8
Samsung SM-A750F Android 10
Pixel 3 Android 11
Samsung Galaxy Tab A8 Android 13

Relevant issue: #2146

@aranda-adapptor
Copy link

Thanks for submitting @hubatruck. We can confirm that the update works well for our use case, and means all permission checks can be removed once targeting SDK 34. We haven't tested this update when targeting versions prior 34 though.

@Darex1991
Copy link

@hubatruck Am I doing something wrong? I have errors:

react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java:28: error: cannot find symbol
import androidx.activity.result.PickVisualMediaRequest;

react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java:30: error: cannot find symbol
import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia;

react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java:31: error: cannot find symbol
import androidx.activity.result.contract.ActivityResultContracts.PickMultipleVisualMedia;

react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java:126: error: package PickVisualMedia does not exist
				PickVisualMedia.VisualMediaType mediaType;

I have target SDK 34 and I added to app/build.gradle

implementation("androidx.activity:activity:1.9.0")
implementation("androidx.activity:activity-compose:1.9.0")
implementation("androidx.activity:activity-ktx:1.9.0")

@hubatruck
Copy link
Contributor Author

@hubatruck Am I doing something wrong? I have errors:

react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java:28: error: cannot find symbol
import androidx.activity.result.PickVisualMediaRequest;

react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java:30: error: cannot find symbol
import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia;

react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java:31: error: cannot find symbol
import androidx.activity.result.contract.ActivityResultContracts.PickMultipleVisualMedia;

react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java:126: error: package PickVisualMedia does not exist
				PickVisualMedia.VisualMediaType mediaType;

I have target SDK 34 and I added to app/build.gradle

implementation("androidx.activity:activity:1.9.0")
implementation("androidx.activity:activity-compose:1.9.0")
implementation("androidx.activity:activity-ktx:1.9.0")

Hi @Darex1991

Could you please give a bit more information about your issue?

I have ran the project with the example application which also uses Kotlin, and it was not throwing me this kind of error. So it seems like react-native has androidx.activity dependency already included, and no need for additional action. Running ./gradle app:dependencies inside the example/android folder also confirmed this.

For easier debugging, the best would be a minimal project that reproduces the issue you mentioned.

@janithl
Copy link

janithl commented Jul 25, 2024

@Darex1991 try adding these to react-native-image-picker's android/build.gradle:

implementation "androidx.core:core:1.3.1"
implementation "androidx.activity:activity:1.6.0"
implementation "androidx.fragment:fragment:1.5.7"

@janithl
Copy link

janithl commented Jul 25, 2024

@hubatruck First of all, thank you for this fix! It's been a lifesaver.

I'm having an issue on Android 11/12 where the ACTION_OPEN_DOCUMENT is fired and the user is asked to give the app permission to access the media files once an image is selected. Do you know if this violates Google's new photo and video policy?

@Darex1991
Copy link

@janithl this helped me! Thanks.
Do you know if I still need to check READ_EXTERNAL_STORAGE permission?
For now, on Androids < 13, I check [PERMISSIONS.IOS.PHOTO_LIBRARY, PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE]

@janithl
Copy link

janithl commented Jul 25, 2024

@Darex1991 I'm glad I could help. I'm not 100% sure about the usage of READ_EXTERNAL_STORAGE for older versions of Android either, but I've been looking at expo packages and they seem to use it with a android:maxSdkVersion="32" in their manifests.

The Photo Picker also falls back to opening documents on older versions of Android if the modular component is not available, which seems to require some sort of read permission:

If the photo picker isn't available on a device, the library automatically invokes the ACTION_OPEN_DOCUMENT intent action instead. This intent is supported on devices that run Android 4.4 (API level 19) or higher. You can verify whether the photo picker is available on a given device by calling isPhotoPickerAvailable().

@janithl
Copy link

janithl commented Jul 25, 2024

@Darex1991 I hope this post from the Android Developers blog is helpful: https://medium.com/androiddevelopers/permissionless-is-the-future-of-storage-on-android-3fbceeb3d70a

@Darex1991
Copy link

@janithl I only noticed adding implementation "androidx.activity:activity:1.6.0" increasing my build twice 36MB -> 72MB

@leblancexplores
Copy link

@janithl I only noticed adding implementation "androidx.activity:activity:1.6.0" increasing my build twice 36MB -> 72MB

Are you using AAB or APK distribution?

@jenskuhrjorgensen
Copy link

@Johan-dutoit is there any chance that this PR can get reviewed and merged before October 31'st? 🤞 Otherwise, we will no longer be able to publish updates to our app (as we don't really have good reasons for having the READ_MEDIA_IMAGES permissions in our app) 😞

@jenskuhrjorgensen
Copy link

jenskuhrjorgensen commented Oct 14, 2024

@Johan-dutoit @marcshilling (I know its been a long time since you contributed to this lib) @brentvatne: Desperate times call for desperate tags <3

I'm sure you have a lot of other important stuff but the change in this PR is becoming more and more critical. If it is not merged and released before end of October it will block people from releasing updates to their apps in Google Play Store and will force people to look for other similar libs (not that I've been able to find good alternatives), write their own lib or try out the risky pursuit of applying this PR as a patch or fork.

@marcshilling
Copy link
Contributor

@jenskuhrjorgensen I can get this merged and a new version released but I don't have capacity to review/test this at the moment. Can you confirm/approve this PR is good as-is? Is this a breaking change that warrants a new major version?

@jenskuhrjorgensen
Copy link

@marcshilling thanks a lot for your quick reply 🤗

I will try to find time to review and test it asap!

In the meantime:
@Darex1991 @hubatruck @janithl are your discussions in this PR resolved? You were talking about having to add some dependencies to app/build.gradle in order for it to work. I'm not really sure I understood if you came to conclusion. Are those dependencies something that is required for this PR to work and if so should it be added to the lib or README?

@janithl you also wrote:

I'm having an issue on Android 11/12 where the ACTION_OPEN_DOCUMENT is fired and the user is asked to give the app permission to access the media files once an image is selected. Do you know if this violates Google's new photo and video policy?

Did you come to a conclusion on this? Is it an issue?

Thanks all for testing and discussing on this - it all helps in getting it merged and released <3

@janithl
Copy link

janithl commented Oct 16, 2024

@jenskuhrjorgensen we added a check for PickVisualMedia.isPhotoPickerAvailable() to see if the photo picker was actually available and fallback to using the document picker new Intent(Intent.ACTION_GET_CONTENT, null) in case it wasn't. We also had to add the READ_EXTERNAL_STORAGE permission for SDK versions less than 32.

Not 100% sure if it will run afoul of Google's policies, but that was the only way we found to make it work on older versions of Android where the new photo picker wasn't available.

@SMPinCode
Copy link

I have forked this and tested on android Api level 34, 30, 29. Works fine.
I should note that I am still using READ_EXTERNAL_STORAGE for versions <= 32

@Darex1991
Copy link

Same as @SMPinCode, but still double size of my apk.
@spacesuitdiver APK

@marcshilling
Copy link
Contributor

Hmm, well I just realized I don't have any permissions on this repo anymore 😞. If someone can bring me back into the fold, I'll get this merged and a new version released. Until then though I can't help.

</activity>

<!-- Trigger Google Play services to install the backported photo picker module. -->
<service android:name="com.google.android.gms.metadata.ModuleDependencies" android:enabled="false" android:exported="false">

Choose a reason for hiding this comment

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

When I open this file in Android Studio I get this warning:
Screenshot 2024-10-22 at 15 47 27

It looks like you missed the tools:ignore="MissingClass" property from the official documentation:
https://developer.android.com/training/data-storage/shared/photopicker

For that to work you also need to add the tools namespace in the top of this file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

README.md Outdated

#### Targeting below Android API v30

Check if your application meets the requirement for AndroidX Photo Picker, otherwise add the entry to your `AndroidManifest.xml`: <https://developer.android.com/training/data-storage/shared/photopicker#device-availability>

Choose a reason for hiding this comment

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

As I understand it this is only required if you want to add backwards compatibility, i.e. be able to use the photo picker on older Android versions https://developer.android.com/training/data-storage/shared/photopicker#device-availability.

And I also believe that for it to work, you need androidx.activity:activity:1.7.+ installed (either directly in your app or transitively via another dependency https://developer.android.com/jetpack/androidx/releases/activity#1.7.0. React Native currently depends on androidx.appcompat:appcompat:1.6.1 which in turn depends on androidx.activity:activity:1.6.0. I think you should add something about this to both the example app and the README. @hubatruck Did the photo picker actually work for you in the example app on Android <30?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest this backwards compatibility part for me is not exactly clear from the docs on how it should work. On the compatible Android APIs it works as expected, and the Photo Picker is showing up.

Did the photo picker actually work for you in the example app on Android <30?

For my Android 8 Samsung device, the fallback documents picker showed up, instead of the new Photo Picker :/

I tried with your suggested changes, but on an Android API 30 emulator, still the system documents picker was showing up.


I honestly have no idea how this backwards compatibility should be configured to work correctly, the Android docs seem too vague.

Choose a reason for hiding this comment

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

I managed to get the backported version to work on older Android versions 🎊

What (primarily) did the trick for me was to test on physical devices (via BrowserStack App Live). I don't know where the limitation in the emulators is. Maybe it has to do with Google Play Services not being updated/installed 🤷

Once, I got this on one of my physical devices (Samsung Galaxy S20 Ultra, Android 10) and I believe this is where it downloads/installs the backported version of the photo picker:
screenshot-Samsung Galaxy S20 Ultra-10 0

Here is proof that the new photo picker works on a Samsung Galaxy S10, Android 9 device:
screenshot-Samsung Galaxy S10-9 0 (1)

Choose a reason for hiding this comment

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

In addition to testing on a physical device, I also had to add this to example/android/app/build.gradle (due to reasons stated earlier in this thread):

...
implementation("com.facebook.react:flipper-integration")

// androidx.activity:activity >= 1.7.0 is required for the backported photo picker to work on Android < 30 https://developer.android.com/jetpack/androidx/releases/activity#1.7.0. 
// This dependency can be removed from here once the react-native library updates androidx.appcompat:appcompat to >= 1.7.0
// https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/gradle/libs.versions.toml#L11
// because androidx.appcompat:appcompat:1.7.0 depends on androidx.activity:activity:1.7.0 https://developer.android.com/jetpack/androidx/releases/appcompat#1.7.0
implementation("androidx.activity:activity:1.7.+")

if (hermesEnabled.toBoolean()) {
...

As this only fixes the example app, I think we should also add a comment about this to the README under the new Targeting below Android API v30 section.

People can test what version of androidx.activity:activity their app depends on with ./gradlew app:dependencies and then look for the first occurrence of androidx.activity:activity. Without implementation("androidx.activity:activity:1.7.+") it looks like this for the example app:

+--- com.facebook.react:react-android -> 0.73.6
|    +--- androidx.appcompat:appcompat:1.6.1
|    |    +--- androidx.activity:activity:1.6.0

With implementation("androidx.activity:activity:1.7.+") it looks like this:

+--- com.facebook.react:react-android -> 0.73.6
|    +--- androidx.appcompat:appcompat:1.6.1
|    |    +--- androidx.activity:activity:1.6.0 -> 1.7.2

In the README, I don't know if we should go this much into details about how to find out about your current version of androidx.activity:activity or if it is enough to say something like:

If your minSdkVersion is < 30 and your app doesn't already depend on/include androidx.activity:activity:1.7.+ then you need to add implementation("androidx.activity:activity:1.7.+") in the dependencies block of your app/build.gradle file in order to support the backported photo picker on Android < 30.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can confirm that on both my Android API <30 shows the backported Photo Picker with the implementation("androidx.activity:activity:1.7.+") line added 🎊

Samsung Galaxy A7 2018 - API 29 "Q"

Manually dragged the Picker a bit down so the app is visible. Otherwise it fills the whole screen.

Samsung SM-A750F

Samsung Galaxy A5 2017 - API 26 "Oreo"

Manually dragged the Picker a bit down so the app is visible. Otherwise it fills the whole screen.

Samsung SM-A520F

If I do not add the line, the fallback documents selector shows up.


I have updated the readme to show the tricks needed. Also added your suggested comment in the example app's build.gradle.

@jenskuhrjorgensen
Copy link

jenskuhrjorgensen commented Oct 22, 2024

@janithl, @SMPinCode and others: Were you actually able to get the new photo picker to work on Android < 30? I've tried to install androidx.activity:activity:1.7.+ due to this but it still doesn't show the new photo picker on my API 29 emulator.

@marcshilling that's a bummer :( But thanks for your good intentions! <3

@SMPinCode
Copy link

@jenskuhrjorgensen I was not getting new photo picker on Android < 30. My mistake i have not mentioned it. I was focused of getting rid of READ_MEDIA_IMAGES. Also I am still using READ_EXTERNAL_STORAGE which covers for APIs <= 32.

@janithl
Copy link

janithl commented Oct 22, 2024

@jenskuhrjorgensen no, I wasn't able to get the new photo picker on the older versions of Android. The document picker was shown instead:

android_screenshot

@hubatruck
Copy link
Contributor Author

@marcshilling thanks a lot for your quick reply 🤗

I will try to find time to review and test it asap!

In the meantime: @Darex1991 @hubatruck @janithl are your discussions in this PR resolved? You were talking about having to add some dependencies to app/build.gradle in order for it to work. I'm not really sure I understood if you came to conclusion. Are those dependencies something that is required for this PR to work and if so should it be added to the lib or README?

@janithl you also wrote:

I'm having an issue on Android 11/12 where the ACTION_OPEN_DOCUMENT is fired and the user is asked to give the app permission to access the media files once an image is selected. Do you know if this violates Google's new photo and video policy?

Did you come to a conclusion on this? Is it an issue?

Thanks all for testing and discussing on this - it all helps in getting it merged and released <3

From my part, the backwards compatibility of the Photo Picker is still a big question. On my API <30 devices & emulators, the documents picker was showing up with the example app. I don't understand what else would be needed for it to work on older APIs.

README.md Outdated

#### Targeting below Android API v30

Check if your application meets the requirement for AndroidX Photo Picker, otherwise add the entry to your `AndroidManifest.xml`: <https://developer.android.com/training/data-storage/shared/photopicker#device-availability>

Choose a reason for hiding this comment

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

I managed to get the backported version to work on older Android versions 🎊

What (primarily) did the trick for me was to test on physical devices (via BrowserStack App Live). I don't know where the limitation in the emulators is. Maybe it has to do with Google Play Services not being updated/installed 🤷

Once, I got this on one of my physical devices (Samsung Galaxy S20 Ultra, Android 10) and I believe this is where it downloads/installs the backported version of the photo picker:
screenshot-Samsung Galaxy S20 Ultra-10 0

Here is proof that the new photo picker works on a Samsung Galaxy S10, Android 9 device:
screenshot-Samsung Galaxy S10-9 0 (1)

README.md Outdated

#### Targeting below Android API v30

Check if your application meets the requirement for AndroidX Photo Picker, otherwise add the entry to your `AndroidManifest.xml`: <https://developer.android.com/training/data-storage/shared/photopicker#device-availability>

Choose a reason for hiding this comment

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

In addition to testing on a physical device, I also had to add this to example/android/app/build.gradle (due to reasons stated earlier in this thread):

...
implementation("com.facebook.react:flipper-integration")

// androidx.activity:activity >= 1.7.0 is required for the backported photo picker to work on Android < 30 https://developer.android.com/jetpack/androidx/releases/activity#1.7.0. 
// This dependency can be removed from here once the react-native library updates androidx.appcompat:appcompat to >= 1.7.0
// https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/gradle/libs.versions.toml#L11
// because androidx.appcompat:appcompat:1.7.0 depends on androidx.activity:activity:1.7.0 https://developer.android.com/jetpack/androidx/releases/appcompat#1.7.0
implementation("androidx.activity:activity:1.7.+")

if (hermesEnabled.toBoolean()) {
...

As this only fixes the example app, I think we should also add a comment about this to the README under the new Targeting below Android API v30 section.

People can test what version of androidx.activity:activity their app depends on with ./gradlew app:dependencies and then look for the first occurrence of androidx.activity:activity. Without implementation("androidx.activity:activity:1.7.+") it looks like this for the example app:

+--- com.facebook.react:react-android -> 0.73.6
|    +--- androidx.appcompat:appcompat:1.6.1
|    |    +--- androidx.activity:activity:1.6.0

With implementation("androidx.activity:activity:1.7.+") it looks like this:

+--- com.facebook.react:react-android -> 0.73.6
|    +--- androidx.appcompat:appcompat:1.6.1
|    |    +--- androidx.activity:activity:1.6.0 -> 1.7.2

In the README, I don't know if we should go this much into details about how to find out about your current version of androidx.activity:activity or if it is enough to say something like:

If your minSdkVersion is < 30 and your app doesn't already depend on/include androidx.activity:activity:1.7.+ then you need to add implementation("androidx.activity:activity:1.7.+") in the dependencies block of your app/build.gradle file in order to support the backported photo picker on Android < 30.

@jenskuhrjorgensen
Copy link

@SMPinCode @janithl I haven't been able to reproduce any issues without the READ_EXTERNAL_STORAGE permission. I even tried to completely remove WRITE_EXTERNAL_STORAGE from the manifest file (both on this branch but also on master of this repo) and I was still able to "Select Image" in the example app. Can you please elaborate on the issues you are facing when not setting this permission and on what devices you are experiencing this?

During testing I also removed WRITE_EXTERNAL_STORAGE as it will imply the READ_EXTERNAL_STORAGE permission https://stackoverflow.com/a/15270626/3749432. This breaks the "Take image" functionality, but not the "Select Image" - at least not in a way that I have been able to find yet...

@SMPinCode
Copy link

@jenskuhrjorgensen I have tried removing WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE on my app, but there are other libraries which are using these permissions and merged or packaged AndroidManifests gets these permissions in. I have not tried the example app yet. I will see if i have time tomorrow

@jenskuhrjorgensen
Copy link

@SMPinCode I believe you can explicitly remove permissions with

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove"/>

@jenskuhrjorgensen
Copy link

@jenskuhrjorgensen I can get this merged and a new version released but I don't have capacity to review/test this at the moment. Can you confirm/approve this PR is good as-is? Is this a breaking change that warrants a new major version?

And I don't believe this is a breaking change. The API didn't change, no dependencies changed, and if you are running Android < 30, you will just fallback to the old document picker. Newer OS'es will get the new photo picker. If you are running Android < 30 and you would like the new backported photo picker you have to add a few additional lines. This will be described in the README.

- update permission
- update docs
Copy link
Contributor Author

@hubatruck hubatruck left a comment

Choose a reason for hiding this comment

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

Thank you @jenskuhrjorgensen for your support and debugging efforts 🙏

README.md Outdated

#### Targeting below Android API v30

Check if your application meets the requirement for AndroidX Photo Picker, otherwise add the entry to your `AndroidManifest.xml`: <https://developer.android.com/training/data-storage/shared/photopicker#device-availability>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can confirm that on both my Android API <30 shows the backported Photo Picker with the implementation("androidx.activity:activity:1.7.+") line added 🎊

Samsung Galaxy A7 2018 - API 29 "Q"

Manually dragged the Picker a bit down so the app is visible. Otherwise it fills the whole screen.

Samsung SM-A750F

Samsung Galaxy A5 2017 - API 26 "Oreo"

Manually dragged the Picker a bit down so the app is visible. Otherwise it fills the whole screen.

Samsung SM-A520F

If I do not add the line, the fallback documents selector shows up.


I have updated the readme to show the tricks needed. Also added your suggested comment in the example app's build.gradle.

@SMPinCode
Copy link

@SMPinCode I believe you can explicitly remove permissions with

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove"/>

@jenskuhrjorgensen
I have tried on emulator API_29_GoogleAPis_Android_10 on my app by explicitly removing permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove"/>
I have also did not get backported android photo picker (because emulator?).
So camera upload works and the documents picker shows up:
image
image

@chr4ss12
Copy link

chr4ss12 commented Oct 24, 2024

       // https://developer.android.com/training/data-storage/shared/photopicker
        if (isSingleSelect) {
            libraryIntent = new PickVisualMedia().createIntent(this.reactContext.getApplicationContext(), mediaRequest);
        } else {
            PickMultipleVisualMedia pickMultipleVisualMedia = selectionLimit > 1
                    ? new PickMultipleVisualMedia(selectionLimit)
                    : new PickMultipleVisualMedia();
            libraryIntent = pickMultipleVisualMedia.createIntent(this.reactContext.getApplicationContext(), mediaRequest);
        }

the selectionLimit > 1 will always be true if !isSingleSelect, so there is no point in conditional.

@jenskuhrjorgensen
Copy link

       // https://developer.android.com/training/data-storage/shared/photopicker
        if (isSingleSelect) {
            libraryIntent = new PickVisualMedia().createIntent(this.reactContext.getApplicationContext(), mediaRequest);
        } else {
            PickMultipleVisualMedia pickMultipleVisualMedia = selectionLimit > 1
                    ? new PickMultipleVisualMedia(selectionLimit)
                    : new PickMultipleVisualMedia();
            libraryIntent = pickMultipleVisualMedia.createIntent(this.reactContext.getApplicationContext(), mediaRequest);
        }

the selectionLimit > 1 will always be true if !isSingleSelect, so there is no point in conditional.

@chr4ss12 I think boolean isSingleSelect = selectionLimit == 1; and selectionLimit > 1 means that new PickMultipleVisualMedia() will be used if selectionLimit == 0 (or actually just < 1) which is described in the README to be used for unlimited selection. So I think the check makes sense.

@chr4ss12
Copy link

chr4ss12 commented Oct 24, 2024

ignore what i said, was too early in the morning, but i am about to test the whole PR in production to see if there are any problems! October deadline is getting close.

@jenskuhrjorgensen
Copy link

@brentvatne and @Johan-dutoit please please please give this PR a short review or even just an approval 🙏🙏🙏

It is crucial that we get this merged and released before Google will prevent ALL OF US from releasing updates next week (October 31'st). Otherwise, people will have to start using forks of this PR 😭 For me that is not even an option, because our build servers are behind a company proxy, so I will not be able to use a fork directly from GitHub.

* https://github.com/facebook/react-native/blob/3dfe22bd27429a43b4648c597b71f7965f31ca65/packages/react-native/gradle/libs.versions.toml#L11
* because androidx.appcompat:appcompat:1.7.0 depends on androidx.activity:activity:1.7.0 https://developer.android.com/jetpack/androidx/releases/appcompat#1.7.0
*/
implementation("androidx.activity:activity:1.7.+")

Choose a reason for hiding this comment

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

Hi @hubatruck
I actually just discovered that the multi select is not working on older Android devices. It looks like there has been several fixes to the photo picker since v1.7, and specifically v1.8.2 fixed the multi select on older Android devices:
https://developer.android.com/jetpack/androidx/releases/activity#1.8.2

So I think we should change

implementation("androidx.activity:activity:1.7.+")

to

implementation("androidx.activity:activity:1.9.+")

And then update the comment section here as well as the README. (there is not yet a version of androidx.appcompat:appcompat that depends on androidx.activity:activity:1.9.+)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the docs, and upon testing, seems like it works with the new version too, and fixes the multiple selection bug

@chr4ss12
Copy link

chr4ss12 commented Nov 4, 2024

i have not heard much feedback from users since releasing to production, thats always good sign.

one feedback from an user:

""In this screenshot, you should see an additional "Browse..." option if you've enabled it properly in Android Media Picker code. Since you decided to switch to the media picker before it was ready to be used, you must manually enable this option. Otherwise, we as users are forced to scroll through however many photos are on our device in reverse date order or copy the desired photo to the very few albums media picker can actually see""

does anyone know what option he is referring to?

@jenskuhrjorgensen
Copy link

@chr4ss12 can you share the screenshot too? What version of androidx.activity:activity did you use?

@chr4ss12
Copy link

chr4ss12 commented Nov 4, 2024

the screenshot I have from the user:

image

I did not use the latest activity, but the one before. I will try to update to latest

@jenskuhrjorgensen
Copy link

@chr4ss12 I tried to spin up the photo picker in a vanilla native Android app as per the official documentation and this is what the photo picker looks like:
Screenshot 2024-11-04 at 20 28 10

However, if I change the test app a bit to use registerForActivityResult(ActivityResultContracts.GetContent()) instead of registerForActivityResult(PickMultipleVisualMedia()) as per this StackOverflow post I can get the picker to show up a "browse" button in the "..." menu:
Screenshot 2024-11-04 at 20 29 37

And when I press "browse" I end up here and it looks like I can pick whatever file(s) I want here:
Screenshot 2024-11-04 at 20 33 21

If I go into the Gmail app on my personal device (Pixel 8, Android 14) and try to attach an image, the picker looks exactly like the one your user complained about ("..." menu with a "Cloud media app" button), so I'm not sure there is anything wrong with this implementation. Also, I'm not sure what your user means by "Since you decided to switch to the media picker before it was ready to be used", since I cannot see anything about the photo picker being experimental or in pilot.

@Johan-dutoit Johan-dutoit merged commit 5856c76 into react-native-image-picker:main Nov 28, 2024
1 check passed
@Johan-dutoit
Copy link
Collaborator

🎉 This PR is included in version 7.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@efstathiosntonas
Copy link

@Johan-dutoit hi, this is not included in the release notes, just fyi

@Johan-dutoit
Copy link
Collaborator

Thanks @efstathiosntonas , semantic release didn't like the "refactor" for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.