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.
Step 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.
Any Questions?
We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.