In order to support OS versions older than Android Froyo/v2.2, it may be necessary to rely on the older deprecated function, getOrientation()
. Below is a brief snippet of code illustrating dynamic function binding. Please note that getOrientation()
may disappear from future Android versions, so it may be most prudent to dynamically bind against both functions and use the one that is available.
WindowManager wm; Method getRotation; wm = (WindowManager)this.getSystemService(WINDOW_SERVICE); Class<Display> c = (Class<Display>)wm.getDefaultDisplay().getClass(); Method[] methods = c.getDeclaredMethods(); String rotFnName = new String("getRotation"); for( Method method : methods ) { Log.d("Methods", method.getName()); if( method.getName().equals( rotFnName )) { getRotation = method; break; } } int orientation; Display display = wm.getDefaultDisplay(); if( getRotation != null ) { try { Integer i = (Integer)getRotation.invoke(d); orientation = i.intValue(); } catch(Exception e) {} } else { orientation = display.getOrientation(); }
NVIDIA® GameWorks™ Documentation Rev. 1.0.220830 ©2014-2022. NVIDIA Corporation and affiliates. All Rights Reserved.