androidkotlin-coroutinesandroid-package-managersandroid-jetpack-compose

How to initialize or access packageManager out from coroutineContext?


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 ?


Solution

  • 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