如何从 coroutineContext 初始化或访问 packageManager?

How to initialize or access packageManager out from coroutineContext?

我有一个 Jetpack Compose 项目,但我只能访问 coroutineContext 对象。此处没有 context

如何访问或初始化 android.content.pm.PackageManager?

您可以从 ContextAmbient.current 获取上下文对象,使用它您可以获取 PackageManager

示例:

val context = ContextAmbient.current
val packageManager = context.packageManager