How to determine the orientation of an Android device
A step by step guide to determining the orientation of an Activity or Composable Android device using Kotlin and Jetpack Compose.


A step by step guide to determining the orientation of an Activity or Composable Android device using Kotlin and Jetpack Compose.
SubscribeDownload Open Source Kotlin Starter ProjectStep One: Create the Utility

In the Android Studio project, create a file called getOrientation.kt and paste in the code below.
Please note that there are two functions as one can be called anywhere whilst the other can only be called within a Composable.
Step Two: Determine the Orientation

Apply the function in your project and determine the orientation using code similar to the sample code provided below.
Step Three: Test

Run the app and rotate the device or emulator and witness how the logs show the orientation of the device.