Thread
#compose
    Bruno_

    Bruno_

    2 years ago
    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
    bezrukov

    bezrukov

    2 years ago
    1. Is it related to compose? 2. Is it related to kotlin?
    Bruno_

    Bruno_

    2 years ago
    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
    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
    Michal Bacik

    Michal Bacik

    2 years ago
    Load file from uri:
    context.contentResolver.openInputStream(uri)?.use { it.readBytes() }
    Why would you start new activity for that?
    Bruno_

    Bruno_

    2 years ago
    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
    )
    Michal Bacik

    Michal Bacik

    2 years ago
    Maybe change question to "how to call other activity from Compose and get result".
    Bruno_

    Bruno_

    2 years ago
    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
    david.bilik

    david.bilik

    2 years ago
    i still cant see how is that related to Compose or Kotlin
    Bruno_

    Bruno_

    2 years ago
    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

    Ryan Mentley

    2 years ago
    Compose doesn't have a dedicated navigation solution yet, but we're planning to have one at some point