What’s the correct way to show chooser to the user...
# compose
r
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
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
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
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
Btw you might consider using the Photo Picker: https://developer.android.com/training/data-storage/shared/photopicker
c
this has some easy samples on how to use photo picker
r
Thanks! 🙇
s
Uhm is the modernstorage link the correct one? I thought this does a very different thing? 😅
c
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
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
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
Yep, all built in now, see the issue tracking the deprecation in ModernStorage: https://github.com/google/modernstorage/issues/94
s
Awesome, this makes total sense now!