- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is really a heads up to others who might be trying to get this plugin working.
The workaround is to use CLI 5.1.1 (I have not tested on other platforms, just IOS)
	I did test on Early Access, which has the same issues.
I wanted to lock the orientation to only one type of landscape. I was struggling to get this plugin working, and finally I decided to try CLI 5.1.1 and that works
    document.addEventListener("deviceready", onDeviceReady, false);               
	    function onDeviceReady(){
	      window.screen.lockOrientation('landscape-secondary')
	      alert("Current orientation: " + window.screen.orientation);
	    }
https://github.com/gbenvenuti/cordova-plugin-screen-orientation
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try this code, the API appears to vary as a function of the platform:
app.testToggleOrientation = function() {
    "use strict" ;
    var fName = "toggleOrientation():" ;
    console.log(fName, "entry") ;
    var str = "" ;
    var screenOrientation = "unknown" ;
    if( window.cordova ) {
        try {
            if( cordova.platformId.match(/ios/i) ) {
                screenOrientation = screen.orientation ;
            }
            else if( cordova.platformId.match(/android/i) ) {
                screenOrientation = screen.orientation.type ;
            }
            else {
                screenOrientation = "unknown" ;
            }
            if( screenOrientation.match(/landscape/i) ) {
                screenOrientation = "portrait" ;
                screen.lockOrientation(screenOrientation) ;
            }
            else if( screenOrientation.match(/portrait/i) ) {
                screenOrientation = "landscape" ;
                screen.lockOrientation(screenOrientation) ;
            }
            else {
                screenOrientation = "unlocked" ;
                screen.unlockOrientation() ;
            }
            str = "try succeeded, screen orientation set to: " + screenOrientation ;
            console.log(fName, str) ;
        }
        catch(e) {
            str = "try failed: " + e ;
            console.log(fName, str) ;
            alert(str) ;
        }
    }
    console.log(fName, "exit") ;
} ;
app.windowEventOrientationChange = function() {
    "use strict" ;
    var fName = "windowEventOrientationChange():" ;
    var str = "" ;
    var screenOrientation = "unknown" ;
    if( window.cordova ) {
        if( cordova.platformId.match(/ios/i) )
            screenOrientation = screen.orientation ;
        else if( cordova.platformId.match(/android/i) )
            screenOrientation = screen.orientation.type ;
    }
    str = "Screen orientation is: " + screenOrientation ;
    console.log(fName, str) ;
} ;
window.addEventListener("orientationchange", app.windowEventOrientationChange) ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks very much for taking the time Paul. I was not aware we could access it like this.
Jason
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I only ran into it because I created a demo app using it and discovered this problem, couldn't find anything in the plugin docs, but figured it out by looking at the plugin code.
 
					
				
				
			
		
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page