Android: Get physical device orientation in a portrait-only app
<p>My app is locked into portrait orientation only, however in one fragment I have a camera preview where I would like to rotate captured images based on the device orientation. I believe that because my app is portrait only, the following code always logs zero. </p>

<pre><code>Display display = ((WindowManager)getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
Log.i(TAG, "Rotation: " + rotation );
</code></pre>

<p>Is it possible to get the actual orientation of the device while locking the app to portrait?</p>

<p>I am targeting android 4.0+ so I'm not concerned if the solution won't work on older devices. </p>
