is there any way to to load a file other than `st...
# compose
b
is there any way to to load a file other than
startActivityForResult
? technically I could make everything that I need global, but it would cause spaghetti code
b
1. Is it related to compose? 2. Is it related to kotlin?
b
I think so, because that's the only way I know of which won't work in compose cus it doesn't use activities (which is required to use startActivityForResult)
am using something like that after all
Copy code
val context = +ambient(ContextAmbient)
context.startActivity(Intent(context, CustomActivityClass::class.java))
CustomActivityClass
has implemented
onActivityResult
which listens for a file
don't like the way I solved it cause will have to store the file as a global state but can't think of anything else
m
Load file from uri:
context.contentResolver.openInputStream(uri)?.use { it.readBytes() }
Why would you start new activity for that?
b
well it works nicely as long as you have the uri, the thing is how do I obtain it
it's my bad because I didn't mention it - I want to be able to pick a file from file browser (that's what I mean by
load a file
)
m
Maybe change question to "how to call other activity from Compose and get result".
👆 1
b
Anyway, if anyone would like to launch a file picker, that's more or less it: https://pastebin.com/embed_iframe/DAgXkFi7 probably not the best solution as I'm new to android, but it gets the job done
d
i still cant see how is that related to Compose or Kotlin
b
isnt it written in kotlin nor using compose? I just assumed that there must be other, compose-specific way to do such thing (and by that I mean a component, like
TopAppBar
), turned out there is not even tho one would help
I'm not using anything compose specific in that pastebin snippet, but it's made for composable functions, you just have to provide context
r
Compose doesn't have a dedicated navigation solution yet, but we're planning to have one at some point