, , ( :). , ( ).
== ,
( ,... , ).
, / ( , 2 ).
int getScreenOrientation(Activity ctx) {
Point pt = new Point(0,0);
try {
Display dsp = ctx.getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
dsp.getSize(pt);
} else {
pt.x = dsp.getWidth();
pt.y = dsp.getHeight();
}
return (pt.x <= pt.y) ?
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT :
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
catch (Exception e) {}
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
}
This only solves the orientation problem, it does not detect if it is a tablet. In fact, most of my 7inch tabs have no problem with orientation mismatch. I found it only on my NEXUS 10 and on the TV android.
"Do not code like me, and everything will be fine with me."
Sean
source
share