Javatpoint Logo
Javatpoint Logo

Cordova Plugin Screen Orientation

This Cordova plugin mainly works for the orientation of the device screen. It is used to set or lock the screen orientation for Windows, iOS, and Android platforms. This plugin is based on the Screen Orientation API, due to this, API matches to the current specification.

Installation:

To add this plugin in your app, you have to install it by typing the below command:

Supported Orientations

  • portrait-primary: It is a primary portrait mode orientation.
  • portrait-secondary: It is a secondary portrait mode orientation.
  • landscape-primary: It is a primary landscape mode orientation.
  • landscape-secondary: It is a secondary landscape mode orientation.
  • portrait: It is either a portrait-primary or portrait-secondary mode orientation.
  • landscape: It is either the landscape-primary or landscape-secondary mode orientation.
  • any: It supports all the orientations (orientation is unlocked).

Usage:

Events:

The orientationchange event is fired from the Android and iOS platforms on the window object. The current version of this plugin allows a user to use the window object for receiving the notifications.

Example:

Android Notes:

For the Android platform, when the device is rotated 180 degrees, screen.orientation property does not update.

Windows UWP Notes:

When we talk about the Windows platform, Windows-UWP (Windows Store Apps) only displays the changed orientation, if the device consists some sort of accelerometer. It remains in the internal state of the orientation, but the device screen does not rotate unless the device supports it.

Code

HTML:

JavaScript:

Output:

Cordova Plugin Screen Orientation




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA