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?
Determine Screen Size :
Determine density:
for Ref: http://devl-android.blogspot.in/2013/10/wifi-connectivity-and-hotspot-in-android.html
If you are in a non-activity i.e. Fragment, Adapter, Model class or any other java class that do not extends
Activity
simplygetResources()
will not work. You can usegetActivity()
in fragment or usecontext
that you pass to the corresponding class.I would recommend making a class say Utils that will have method/Methods for the common work. The benefit for this is you can get desired result with single line of code anywhere in the app calling this method.
I need this for a couple of my apps and the following code was my solution to the problem. Just showing the code inside onCreate. This is a stand alone app to run on any device to return the screen info.
And a simple XML file
I must be missing something. DisplayMetrics.widthPixels, DisplayMetrics.heightPixels?
http://developer.android.com/reference/android/util/DisplayMetrics.html#heightPixels
[EDIT]
Ah, I am missing something. A brain! +1 for Alex.
simon-
Different screen sizes have different pixel densities. A 4 inch display on your phone could have more or less pixels then say a 26 inch TV. If Im understanding correctly he wants to detect which of the size groups the current screen is, small, normal, large, and extra large. The only thing I can think of is to detect the pixel density and use that to determine the actual size of the screen.