How to get Context in Jetpack Compose How to get Context in Jetpack Compose android android

How to get Context in Jetpack Compose


Update March 2021: The previous answer has been deprecated. You should now use:

val context = LocalContext.current

Previous answer for reference:

You can access to context with define ambientContext.

Example:

val context = ContextAmbient.current


ContextAmbient and AmbientContext is deprecated

You can replace them with

val context = LocalContext.current


ContextAmbient.current is deprecated as of alpha-09.

AmbientContext.current is deprecated. I think as of alpha-11.

LocalContext.current is how you get the context in a composable now.