How do I use jetpack compose to select images from...
# compose
n
How do I use jetpack compose to select images from my phone album to add to the user interface?ย (edited)
a
The
androidx.activity:activity-compose
library has this API under development in the latest alpha version: https://developer.android.com/reference/kotlin/androidx/activity/compose/package-summary#registerforactivityresult
๐Ÿ‘ 1
n
thank you very much!!๐Ÿ‘
๐Ÿ‘ 1
@Adam Powell But this seems to only take photos, how do I get the photos in the album and apply them to the interface?
a
It can perform any startActivityForResult operation on the system as well as request permissions. What kind of UI are you looking to implement? The approach will be different if you want to launch a system picker for the user to choose a photo (ACTION_GET_CONTENT, iirc) vs. show your own picker UI inline in the rest of your app (request storage/photos permissions and then read the media provider)
s
use
ActivityResultContracts.OpenDocument()
and launch it like this
Copy code
launch(arrayOf("image/*"))
a
the former is much easier to implement and doesn't require holding additional permissions that might make users nervous, the latter can be more seamless/customized within your app.
n
yes like twitter share, in bottom have some application to choice
I've solved the problem, I need to learn the basics of intent @Adam Powell thank you very much for your help!
s
@Adam Powell Will there be any image/video/document picking androidx lib at some point? because it's super common task, and 99 percent of StackOverflow solutions are wrong.
n
yes
by the way, when do I create a LazyColumn item that can be reordered by drag and drop? Does jetpack compose develop?
a
I would start a new thread for the drag+drop question
n
ok sir
a
@Shakil Karim it's a request we get a lot, but every time we start digging into specifics, everyone wants some pretty fine-grained control over the UI design itself ๐Ÿ™‚
discussions are underway and input definitely welcome, but no specific plans to share at this time
๐Ÿ‘ 1
n
its ok, very good!
๐Ÿ‘ 1
jetpack compose is very amazing
a
thank you ๐Ÿ™‚ we anticipate many years of building onto the base functionality available today, and we're looking forward to a healthy ecosystem of community libraries in addition to our own
n
Its syntax is so much better than Dart
Looking forward to it!
@Adam Powell One more question, if what I want to share is an image, how can I make this interface an image to share to other apps via Intent? Is there any good way to do this?
This is an interface I developed using jetpack compose, what if I want to share the content as an image?
a
I think there are some other threads above around saving content to a bitmap
once you have that bitmap you can share it using a FileProvider or similar
n
ok i check it
very thx
๐Ÿ‘ 1
you can get a ContentResolver from a Context