Screen Resolution refers to the number of pixels on display. A higher resolution means more pixels and more pixels provide the ability to display more visual information. This entity is widely used in applications related to the broadcasting of real-time visuals such as a live video, gaming, etc for the optimization and frame conversions. The same information can also be used to detect if there is damage to any of the pixels present on the screen. Practically, it is possible to retrieve this information. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Kotlin language.
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.
Step 2: Working with the activity_main.xml file
Go to the activity_main.xml file which represents the UI of the application, and create a Button which on click would generate a Toast displaying the number of pixels available at the width and length. Below is the code for the activity_main.xml file.
Step 3: Working with the MainActivity.kt file
Go to the MainActivity.kt file, and refer the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
Output: Run on Emulator
- How to Display the List of Sensors Present in an Android Device Programmatically?
- How to Vibrate a Device Programmatically in Android?
- How to Increase/Decrease Screen Brightness in Steps Programmatically in Android?
- How to Increase/Decrease Screen Brightness using Volume Keys Programmatically in Android?
- How to Detect Touch Event on Screen Programmatically in Android?
- How to Change the Screen Orientation Programmatically using a Button in Android?
- How to Maximize/Minimize Screen Brightness Programmatically in Android?
- How to Keep the Device Screen On in Android?
- How to Add Different Resolution Images in Android Studio?
- How to programmatically hide Android soft keyboard
- Current Internet Connection Type in Real-Time Programmatically in Android
- How to Invoke Keyboard Programmatically in Android?
- How to Obtain the Connection Information Programmatically in Android?
- How to Programmatically Enable/Disable Bluetooth in Android?
- How to Programmatically Enable/Disable Wi-Fi in Android?
- How to Adjust the Volume of Android Phone Programmatically from the App?
- How to Control Lottie Animations Programmatically in Android?
- How to Check the Battery Level in Android Programmatically?
- How to Check if the Battery is Charging or Not in Android Programmatically?
- How to Check the Type of Charging (USB/AC) in Android Programmatically?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.