Hi ! In my application I'm defining a function lik...
# multiplatform
l
Hi ! In my application I'm defining a function like this :
Copy code
expect fun getStartDirectory() : String
Which, on Android should return the application folder as String, and on Desktop (Windows/Linux) should return the content of user.home system property. But on Android I need a Context, while on Desktop I don't need anything in order to compute it. So is there a clean way to handle this ?
โœ… 1
Fore more information : I handle in Desktop with this :
Copy code
actual fun getStartDirectory(): String {
    return System.getProperty("user.home")
}
And on Android I need something like this :
Copy code
actual fun getStartDirectory(): String {
    return context.getApplicationInfo().dataDir
}
where here the main concern is the context value, which can't be declared in the common code.
l
Splitties App Context should help you ๐Ÿ˜‰
l
Thank you : what do you mean by splitting app context ?
l
"Splitting" ?
l
splitties sorry
l
Google it ๐Ÿ˜‰
l
Found this : https://splitties.louiscad.com/modules/appctx/ Thank you. I'll have a look at it
l
Yup, that's it.
implementation("com.louiscad.splitties:splitties-appctx:3.0.0")
should get you going
l
Thank you very much ๐Ÿ™‚ I try it right now ๐Ÿ™‚
Is there in import to add in order to use appCtx ? Fleet from Intellij Idea does not yet give me any.
l
Make sure the dependency is added to androidMain to the right module, make sure Gradle sync was done, and make sure you try to use it in a file in androidMain
l
Ok. I'll do one more Gradle Sync
I've added in android dependencies
Copy code
androidMain.dependencies {
            implementation(compose.preview)
            implementation(libs.androidx.activity.compose)
            implementation(libs.coroutines.android)
            implementation(libs.splitties.app.ctx)
        }
๐Ÿ‘ 1
l
You should then get it with splitties.init.appCtx
๐Ÿ‘ 1
l
Oh : I made a typo in the libs.versions.toml. Hence the fact it could not find it I guess. Still waiting the sync.
All fine : thank you very much ๐Ÿ‘