- Home /
figured it out myself
How to know whether it is android tab or android phone or kindle tab?
is there any way in unity to know whether it is android tab or android phone or kindle tab? i know the DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
ref:: http://developer.android.com/reference/android/util/DisplayMetrics.html isn't there any simpler way I mean unty doesn't have anything inbuilt to get device screen size in inches?
Why don't you post and mark your answer then? That would help others if they come along this question.
sure friend going to post it soon let me more generic first using android api's calls
Answer by robhuhn · Aug 07, 2013 at 10:00 AM
If you need to know the resolution type ldpi, mdpi, hdpi or xhdpi or want to set positions and sizes in dp instead of px I would recommend using a class I wrote some time ago: DisplayMetricsUtil
Get the resolution type:
ResolutionType res = DisplayMetricsUtil.GetResolutionType();
Set a width of 100 dp and convert it to px:
float width = 100f.DpToPixel();
ScreenSize in dp:
Rect screenSizeDp = DisplayMetricsUtil.ScreenSizeDpUnit();
Answer by fafase · Aug 07, 2013 at 09:12 AM
What about
Screen.width;
Screen.height;
I'd used both but are not sufficient.
screeWidthInInches = (Screen.width / Screen.dpi); But ins$$anonymous$$d it gives "infinity" is should be like this float screenWidth = dm.widthPixels / dm.xdpi; float screenHeight = dm.heightPixels / dm.ydpi; double size = $$anonymous$$ath.sqrt($$anonymous$$ath.pow(screenWidth, 2) + $$anonymous$$ath.pow(screenHeight, 2));