Switch to using photo picker
To solve the issue #1261 I apply the logic that is explained here: https://developer.android.com/training/data-storage/shared/photopicker#java
First, I need to look for situations in which the user is allowed to select an image from their gallery or files directory. I found that the user is allowed to select an image in three main cases:
- When creating a card and an icon or image can be defined, or in the Photos tab (to define the front and back image).
- When editing a card and an icon or image can be defined, or in the Photos tab (to define the front and back image).
- When extracting a barcode or QR code.
After identify these cases I search the code that display the gallery or the file directory and I adapt that code to use the new photo picker approach instead the old one (Only if the Android version of the phone is superior to Android R (11), because if I want to apply this approach to old versions of android, I need to enable the automatic installation of the backported photo picker module through Google Play services and the issue says that is better to not install things without the permission of the user and I agree with that).
Basically, I add some dependencies of androidx and edit the next functions:
- addFromImageAfterPermission() - In the ScanActivity
- selectImageFromGallery(int type) - In the LoyaltyCardEditActivity
If the phone had an Android version oldest than 11 then the old code is executed, if not then the new photo picker is used.
I've tested and can tell it works on my Android 13 phone. After testing on an Android 5 emulator I kinda understand your decision to have the two code paths as it somehow opens the file manager on Android 5 instead of the gallery.
I do still prefer just a single code path, also for consistency in behaviour with other apps.
But this needs to be delayed anyway given the Photo Picker currently only shows internal camera images and thus will lack many many images the user my want to select. Maybe it'll get added later.
Thanks for your contribution, it's sad Google hasn't developed the Photo Picker in a way where it'll be useful for most users.