This PhoneGap Plugin for Android can lock/unlock the screen orientation.
-
Add com/tsukurusha/phonegap/plugins/ScreenOrientation.java to your src folder.
-
Add the following line to res/xml/plugins.xml.
<plugin name="ScreenOrientation" value="com.tsukurusha.phonegap.plugins.ScreenOrientation" />
-
Add pg-plugin-screen-orientation.js to your assets/www folder and import it into your html file like:
<script type="text/javascript" charset="utf-8" src="pg-plugin-screen-orientation.js"></script>
-
The javascript interface is as follows:
-
To lock the screen to Landscape:
navigator.screenOrientation.set('landscape');
-
To lock the screen to Portrait:
navigator.screenOrientation.set('portrait');
-
To unlock:
navigator.screenOrientation.set('fullSensor');
-
You can use other orientation parameters defined in http://developer.android.com/reference/android/R.attr.html#screenOrientation