androidandroidxandroid-orientationandroid-displaymanager

How to read current screen orientation on Android?


I would like to read current screen orientation on Android using Jetpack Compose.

I already tried following in a @Composable:

val o = LocalActivity.current.requestedOrientation

val o = LocalContext.current.display.rotation

val o = LocalActivity.current.resources.configuration.orientation

but in vain.

Log.d("Orientation", "The Orientation $o")

Everytime, I rotate the orientation, log outputs on these remain the same. So they do not seem to change.

How can I read the screen orientation?


Solution

  • androidx.compose.ui.platform.LocalConfiguration.current.orientation
    

    solved it for me.