How to determine if an Android device is Landscape or Portrait

Oscar de la Hera Gomez
Four flowers that represent Kotlin, Android, Jetpack Compose and Android Studio side by side. Beneath them sits the text “Landscape or Portrait.”

A step by step guide to determining if an Activity or Composable is landscape or portrait on an Android Device using Kotlin and Jetpack Compose.

Step One: Create the Utility

A screenshot of Android Studio showing the code for determining if an Android device is Landscape or Portrait.

In the Android Studio project, create a file called isLandscape.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: Test

A screenshot of Android Studio showing the emulator in landscape. The logs demonstrate that it was previously portrait and now landscape.

Run the app and rotate the device or emulator and confirm that the function registers landscape and portrait correctly.

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.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details