I have a Jetpack Compose project were I can access a coroutineContext
object only. No context
available here.
How can I access or initialize android.content.pm.PackageManager ?
I have a Jetpack Compose project were I can access a coroutineContext
object only. No context
available here.
How can I access or initialize android.content.pm.PackageManager ?
You can get the context object from ContextAmbient.current
, using that you can get the PackageManager
Example:
val context = ContextAmbient.current
val packageManager = context.packageManager
To get context in Jetpack Compose:
val context = LocalContext.current
And to get packageManager from the context:
val packageManager = context.packageManager
So, if you just want packageManager you can use this:
val packageManager = LocalContext.current.packageManager
And for your information, LocalContext.current
is a composable and need to be called in a composable context.
© 2022 - 2024 — McMap. All rights reserved.
val context = LocalContext.current
– Sulfide