What is the alternative for getRealMetrics in android to get screen original size -


in android application need find out if device having navigation bar or not. getting device original screen size , application window size. based on calculating difference , can find out if device having navigation bar or not. here code use:

public static boolean hassoftkeys(windowmanager windowmanager){     display d = windowmanager.getdefaultdisplay();      displaymetrics realdisplaymetrics = new displaymetrics();     d.getrealmetrics(realdisplaymetrics);      int realheight = realdisplaymetrics.heightpixels;     int realwidth = realdisplaymetrics.widthpixels;      displaymetrics displaymetrics = new displaymetrics();     d.getmetrics(displaymetrics);      int displayheight = displaymetrics.heightpixels;     int displaywidth = displaymetrics.widthpixels;      return (realwidth - displaywidth) > 0 || (realheight - displayheight) > 0; } 

the problem is: calling "getrealmetrics" method requires api level 17. here need solution lower version devices give same result getrealmetrics original screen size. did not find solution.

can suggest me alternative getrealmetrics work lower version devices ?

here investigation find out navigation bar availability. not reliable result on devices.

code1:

boolean hasnavbar(context context) {          boolean hasmenukey = viewconfiguration.get(context).haspermanentmenukey();         boolean hasbackkey = keycharactermap.devicehaskey(keyevent.keycode_back);         return !hasmenukey && !hasbackkey;     } 

code2

boolean hasmenukey = viewconfiguration.get(context).haspermanentmenukey(); 

by using code can check if device has permanentmenukey. not meaning device don't have permanentmenukey having soft navigation bar.

displaymetrics metrics = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(metrics); int width = metrics.widthpixels; int height = metrics.heightpixels; 

Comments