Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the ScreenSize programmatically in android

Android defines screen sizes as Normal Large XLarge etc.

It automatically picks between static resources in appropriate folders. I need this data about the current device in my java code. The DisplayMetrics only gives information about the current device density. Nothing is available regarding screen size.

I did find the ScreenSize enum in grep code here However this does not seem available to me for 4.0 SDK. Is there a way to get this information?

like image 761
user1454356 Avatar asked Jun 28 '12 20:06

user1454356


People also ask

How can get screen width and height in Android programmatically?

Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.


1 Answers

Copy and paste this code into your Activity and when it is executed it will Toast the device's screen size category.

int screenSize = getResources().getConfiguration().screenLayout &         Configuration.SCREENLAYOUT_SIZE_MASK;  String toastMsg; switch(screenSize) {     case Configuration.SCREENLAYOUT_SIZE_LARGE:         toastMsg = "Large screen";         break;     case Configuration.SCREENLAYOUT_SIZE_NORMAL:         toastMsg = "Normal screen";         break;     case Configuration.SCREENLAYOUT_SIZE_SMALL:         toastMsg = "Small screen";         break;     default:         toastMsg = "Screen size is neither large, normal or small"; } Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show(); 
like image 66
Alex Lockwood Avatar answered Oct 04 '22 04:10

Alex Lockwood