Without any code snippet for the application, how to get screen resolution and length of the screen. How could I find whether the device is ldpi, mdpi , hdpi or xhdpi ?
Asked
Active
Viewed 3.2k times
23
-
No, I don't want to code and find the device type ? – Sreeram Feb 25 '13 at 06:49
-
its kind of late but There was this app on the playstore which will get you what you are looking for without writing a code snippet but unfortunately the app is removed from google play store but i was able to extract the apk from my installed device and have uploaded it to following link: https://www.mediafire.com/?2jccjo17mvxgljt Hope this helps you in getting what are you looking for. Do let me know if that helped you or not – Niranjan Balkrishna Prajapati Mar 13 '14 at 07:22
-
If you want a quick reference, Google provides screen details of a few popular devices: https://design.google.com/devices/ – rpattabi Nov 25 '16 at 09:28
2 Answers
72
Edit:
use DisplayMetrics
to get the density of the screen
getResources().getDisplayMetrics().densityDpi;
this will return the int value that represents the following constants.
DisplayMetrics.DENSITY_LOW ,DisplayMetrics.DENSITY_MEDIUM, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_XHIGH
int density= getResources().getDisplayMetrics().densityDpi;
switch(density)
{
case DisplayMetrics.DENSITY_LOW:
Toast.makeText(context, "LDPI", Toast.LENGTH_SHORT).show();
break;
case DisplayMetrics.DENSITY_MEDIUM:
Toast.makeText(context, "MDPI", Toast.LENGTH_SHORT).show();
break;
case DisplayMetrics.DENSITY_HIGH:
Toast.makeText(context, "HDPI", Toast.LENGTH_SHORT).show();
break;
case DisplayMetrics.DENSITY_XHIGH:
Toast.makeText(context, "XHDPI", Toast.LENGTH_SHORT).show();
break;
}
This will return following constants based on thsi you can identify the device
Try this
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch(screenSize) {
case Configuration.SCREENLAYOUT_SIZE_LARGE:
Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
Toast.makeText(this, "Normal screen",Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
Toast.makeText(this, "Small screen",Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show();
}
-
This answer doesn't actually answer the question. It's asking about density, not size. – kabuko Feb 25 '13 at 06:33
-
1
-
I dont want to code - seeing the mobile could I? Purpose : Samsung S4 is coming to market in march - I want to know the density , – Sreeram Feb 25 '13 at 06:48
-
@Sreeram "seeing the mobile" in the sense...you can find the phone spefications in http://www.gsmarena.com/samsung_galaxy_s_iv-5125.php – Pragnani Feb 25 '13 at 06:50
-
@Pragnani - Might be fundamental but please ignore - Using GSM arena, how could I find the device device - Now my objective is to find S4 belongs to HDPI/XHDPI. – Sreeram Feb 25 '13 at 07:36
-
@Sreeram That is what we(me and Gabe Sechan) have posted. I'll update it for you make you clear – Pragnani Feb 25 '13 at 07:50
-
1As per what Gabe and you posted, I need to code the snippet - run it on the device and find the device type. But the requirement is looking at the device , knowing the screen spec's - could I find the device type - I remember a formula not clear [square root of width* height]/length .. blah blah .. if the value is <1 >1 >1.25 >1.50 I could find the device type. Could you explain it for me. – Sreeram Feb 25 '13 at 08:03
2
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int density = dm.densityDpi;
The density variable is a constant defined in DisplayMetrics corresponding to the different dpis.

Gabe Sechan
- 90,003
- 9
- 87
- 127
-
I dont want to code - seeing the mobile could I? Purpose : Samsung S4 is coming to market in march - I want to know the density , – Sreeram Feb 25 '13 at 06:47
-
2Use google and search then. And then you're asking on the wrong site- this is a site for asking programming questions, not about device specs. – Gabe Sechan Feb 25 '13 at 14:01