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

Mehdi Haghgoo

02/17/2021, 1:05 PM
Does Jetpack Compose have easy integration with gallery and storage access for picking files?
🚫 1
🔜 1
i

Ian Lake

02/17/2021, 3:07 PM
It will in the upcoming Activity Compose 1.3.0-alpha03: https://issuetracker.google.com/issues/172690553
m

Mehdi Haghgoo

02/17/2021, 3:09 PM
So, it's not currently possible to access files from Compose. Is it?
z

zsperske

02/17/2021, 3:41 PM
you can probably use
AmbientContext
in some way to do what you want
a

Adam Powell

02/17/2021, 3:50 PM
anything possible from any other part of the android sdk is possible from compose, and we wouldn't do anything in a future stock implementation of a file picker that you can't do yourself from the public api available today. 🙂
👍 3
i

Ian Lake

02/17/2021, 4:49 PM
You can certainly copy/paste the CL in that issue into your app
s

Samir Basnet

02/17/2021, 5:09 PM
Does that mean we will be able to pick files/image without requiring that FileUtils class we generally use with methods to obtain filepath for different android versions containing lots of logic?
😱 1
i

Ian Lake

02/17/2021, 5:14 PM
That's absolutely never something you need to do on any API level. You should always be using
ContentResolver
APIs to open an input stream from the returning URI
👍 2
s

Samir Basnet

02/18/2021, 2:44 AM
But i have searched a lot and only found gists that handle it differently for different android versions. Can you provide a link to a proper guide or tutorial please?
i

Ian Lake

02/18/2021, 4:14 AM
contentResolver.openInputStream(uri)
is all you need to do to open any URI on any API. That's literally it
s

Samir Basnet

02/18/2021, 4:25 AM
Thank you for the reply. Appreciate answering by noob question
@Ian Lake Ok so it`s throwing error in case when my Uri is like this content://com.android.providers.media.documents/document/image%3A28 . How to handle such Uri ?
i

Ian Lake

02/24/2021, 5:49 PM
Are you doing something other than calling
contentResolver.openInputStream(thatExactUri)
upon receiving that URI?
s

Samir Basnet

02/25/2021, 5:07 AM
@Ian Lake Nope nothing after getting Uri thats the first thing i am doing
<http://java.io|java.io>.FileNotFoundException: No such file or directory
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:691)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1080)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:921)
at android.content.ContentResolver.openInputStream