Android Orientation Changer

Simple plugin to change the android main activity orientation during runtime.
Boy van der Laak0.1.14
platforms: android
$ cordova plugin add com.boyvanderlaak.cordova.plugin.orientationchanger

Android Orientation Changer

Android devices have a lot of different resolutions. Your responsive design might not work for multiple orientations on each of those devices. With this plugin you can lock the orientation on runtime after you get the device dimensions.


Through the Command-line Interface:

cordova plugin add

To remove:

cordova plugin rm com.boyvanderlaak.cordova.plugin.orientationchanger


After cordova and its plugins are loaded you can execute the following line of code to lock the orientation:


You can choose between 'portrait', 'landscape', 'sensor' and 'default'. 'default' being the orientation as configured in your config.xml. The 'sensor' setting forces the orientation to be whatever orientation the device is in, regardless of your setting in config.xml. Note that some devices do not support all four orientations in sensor mode (for example some devices won't normally use 180 degree rotation).

If you want to revert back to default behaviour you can use:

window.plugins.orientationchanger.resetOrientation(); // Note that is the same as doing .lockOrientation('default')

To get the currently enforced orientation:

var currentOrientation = window.plugins.orientationchanger.getOrientation();
if(currentOrientation == 'landscape') {
  // Do something that only happens in landscape
  // Note that .getOrientation() just returns 'default' and not the displayed orientation 
  // if you haven't locked any orientation