https://kotlinlang.org logo
#compose
Title
# compose
r

Rihards

02/20/2023, 1:09 PM
What’s the correct way to show chooser to the user to take a photo or pick image from gallery?
rememberLauncherForActivityResult(ActivityResultContracts.GetMultipleContents())
provides the gallery part, but how to use it in combination with camera?
s

Stylianos Gakis

02/20/2023, 1:15 PM
Such a contract doesn’t seem to exist, but how do you think this would exactly play out? They click your button in the app, and where are they headed? How do they either pick a file or take a photo? Unless I am missing something I think that could be pretty tricky to handle no? Do you have any example apps that do this exact action? Could it be that you can have two buttons each leading to one or the other action?
r

Rihards

02/20/2023, 1:28 PM
Long story short - I have a button “Add photo” that should navigate user to camera or gallery / files where user can either take a photo or pick photos. To understand where user should be navigated I have to display chooser so that user can pick one of the options.
They click your button in the app, and where are they headed?
Chooser displayed. Similar as mentioned in this stackoverflow post.
Do you have any example apps that do this exact action?
I don’t use a lot of international apps, but I know that Notion has the same scenario when try to add photo to the page.
Could it be that you can have two buttons each leading to one or the other action?
Unfortunately in this situation multiple buttons are not an option. 😕
s

Stylianos Gakis

02/20/2023, 1:36 PM
So is there an intent that handles this flow all together? The SOE post is quite long to parse it quickly. If that is the case, you can create your own contract by launching that intent yourself, by copying one of the existing ones as a skeleton and adjust it to your needs.
c

Chris Fillmore

02/20/2023, 2:28 PM
Btw you might consider using the Photo Picker: https://developer.android.com/training/data-storage/shared/photopicker
c

Colton Idle

02/23/2023, 12:00 AM
this has some easy samples on how to use photo picker
r

Rihards

02/23/2023, 6:24 AM
Thanks! 🙇
s

Stylianos Gakis

02/23/2023, 7:01 AM
Uhm is the modernstorage link the correct one? I thought this does a very different thing? 😅
c

Colton Idle

02/23/2023, 2:11 PM
I'm fairly certain thats where I grabbed the photo picker code for my app.
i could be wrong though. it was a few months ago.
s

Stylianos Gakis

02/23/2023, 2:20 PM
Aha, but I thought you can use that naturally through androidx.activity without the need of this library. Read this https://twitter.com/ianhlake/status/1628538469395107840 today for example. What does modernstorage provide on top of this? Or am I misunderstanding something
c

Colton Idle

02/23/2023, 3:08 PM
Not sure actually. I always thought that the modern storage lib gives you a way to backport photo picker. can @yrezgui or @Ian Lake chime in?
i

Ian Lake

02/23/2023, 3:13 PM
Yep, all built in now, see the issue tracking the deprecation in ModernStorage: https://github.com/google/modernstorage/issues/94
s

Stylianos Gakis

02/23/2023, 3:15 PM
Awesome, this makes total sense now!
34 Views