java - How to get the screen's size of a phone Android -
this question has answer here:
- how android device screen size? 6 answers
i want size of screen, have resolution
displaymetrics displaymetrics = new displaymetrics(); windowmanager windowmanager = (windowmanager) getapplicationcontext().getsystemservice(context.window_service); windowmanager.getdefaultdisplay().getmetrics(displaymetrics); final int devicewidth = displaymetrics.widthpixels; final int deviceheight = displaymetrics.heightpixels;
but want size in inches, samsung galaxy s7 has resolution of 2560x1440 , screen of 5.1" , it's 5.1 want get.
thanks
if want display dimensions in pixels can use code:
display display = getwindowmanager().getdefaultdisplay(); int width = display.getwidth(); int height = display.getheight();
then can add condition compares height satisfy needs.
in inches:
displaymetrics dm = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(dm); double x = math.pow(dm.widthpixels/dm.xdpi,2); double y = math.pow(dm.heightpixels/dm.ydpi,2); double screeninches = math.sqrt(x+y); log.d("debug","screen inches : " + screeninches);
Comments
Post a Comment