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 ?
For example, if you have a bitmap drawable that's 48x48 pixels for medium-density screen (the size for a launcher icon), all the different sizes should be: 36x36 for low-density (LDPI) 48x48 for medium-density (MDPI) 72x72 for high-density (HDPI)
The normal mdpi is based on a 160 dpi screen, which again is the same as a single pixel unit in your graphics software. Here's a quick breakdown of the dpi measurements for the different pixel densities: ldpi — 120dpi. mdpi — 160 dpi. hdpi — 240 dpi.
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(); }
Source Identifying screen resolutions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With