tidev / titanium-sdk

🚀 Native iOS and Android Apps with JavaScript
https://titaniumsdk.com/
Other
2.76k stars 1.21k forks source link

feat(android): implement Android Photo Picker #14131

Open m1ga opened 1 month ago

m1ga commented 1 month ago

Will replace the current openPhotoGallery method and use https://developer.android.com/training/data-storage/shared/photopicker

When I was updating an Android app I was asked in the store to use the Photo Picker instead of using <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>. But you could still opt-in for the image permission, so not a high priority for now.

I have to call ActivityResultLauncher in the BaseActivity otherwise I wasn't able to catch the results. And in order to get the results from the BaseActivity back to MediaModule I use a local Broadcast. Not sure if that is the best way to do it but I didn't find another way.

var win = Ti.UI.createWindow();
var img = Ti.UI.createImageView();
win.addEventListener("click", function() {

    Ti.Media.openPhotoGallery({
        allowMultiple:true,
        mediaTypes: Titanium.Media.MEDIA_TYPE_PHOTO, // Titanium.Media.MEDIA_TYPE_VIDEO
        success: function(e) {
            img.image = e.media;
        }
    });

})
win.add(img);
win.open();