Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): implement Android Photo Picker #14131

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Oct 3, 2024

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();

var isMultiple = true;
var isVideo = false;

win.addEventListener("click", function() {
	Ti.Media.openPhotoGallery({
		allowMultiple: isMultiple,
		// maxImages: 2,
		mediaTypes: isVideo ? Titanium.Media.MEDIA_TYPE_VIDEO : Titanium.Media.MEDIA_TYPE_PHOTO,
		success: function(e) {
			if (!isVideo) {
				if (isMultiple) {
					console.log("Multiple images");
					console.log(e.images.length);
					img.image = e.images[0].media;
				} else {
					console.log("Single image");
					img.image = e.media;
				}
			} else {
				console.log("video")
				if (isMultiple) {
					console.log("Multiple videos");
					e.videos.forEach(function(item){
						console.log(item.width, item.height)
					})
				} else {
					console.log("Single video");
					console.log(e.width, e.height)
				}
			}
		}
	});
})

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

@m1ga
Copy link
Contributor Author

m1ga commented Dec 14, 2024

I think I have all parts now 😄 Image, Video, Image & Video. Multiple and single. Multiple with maxImages

@m1ga m1ga marked this pull request as ready for review December 14, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant