Here is code snippet demo how to get screen orientation was recommend by hackbod and Martijn:
? Trigger when change Orientation:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int nCurrentOrientation = _getScreenOrientation();
_doSomeThingWhenChangeOrientation(nCurrentOrientation);
}
? Get current orientation as hackbod recommend:
private int _getScreenOrientation(){
return getResources().getConfiguration().orientation;
}
?There are alternative solution for get current screen orientation ? follow Martijn solution:
private int _getScreenOrientation(){
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
return display.getOrientation();
}
?Note: I was try both implement ? & ?, but on RealDevice (NexusOne SDK 2.3) Orientation it returns the wrong orientation.
?So i recommend to used solution ? to get Screen orientation which have more advantage: clearly, simple and work like a charm.
?Check carefully return of orientation to ensure correct as our expected (May be have limited depend on physical devices specification)
Hope it help,