Software Archive
Read-only legacy content
17061 Discussions

Screen orientation plugin is not working.

Ozgur_O_
Beginner
1,124 Views

Hi all.

I'm using Cordova Screen Orientation Plugin for an iOS app.In my app-init.js file the code blocks below supposed to do the job. But it doesn't.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {

    intel.xdk.device.setRotateOrientation("landscape");
    intel.xdk.device.setAutoRotate(false);

    window.screen.lockOrientation('landscape-primary'); 

}

Also this node is added in the config.xml file : <preference name="Orientation" value="landscape" />

mayday.

0 Kudos
7 Replies
PaulF_IntelCorp
Employee
1,124 Views

Please do not use those old intel.xdk functions, they are not getting updated and are obsolete. Please see this FAQ > https://software.intel.com/en-us/xdk/faqs/cordova#app-orientation

0 Kudos
Ozgur_O_
Beginner
1,124 Views

Ok. Thanks for the info.

However I'm still wondering what is the solution.

The last line in the code block is Cordova Screen Orientation Plugin and it's not deprecated. But it doesan't work anyway.

0 Kudos
Anusha_M_Intel1
Employee
1,124 Views

This screen orientation plugin is the solution - https://github.com/gbenvenuti/cordova-plugin-screen-orientation

Many users have had luck with it. Where exactly is it failing?

If you are facing issues with iPad, create a plugin.xml as instructed in the first part of the FAQ. 

0 Kudos
Ozgur_O_
Beginner
1,124 Views

@Anusha Muthiah , Im also trying that solution can be seen in the codes. But the problem is, it's ok when opening the app but when i change the orientation it changes, doesn't prevent its state.

0 Kudos
PaulF_IntelCorp
Employee
1,124 Views

@Ozgur, I just did an experiment with an Android device and the Debug tab, which is an easy way to experiment with the API to make sure you are using it correctly:

For example, I was able to experiment with:

screen.lockOrientation("portrait-primary")
screen.lockOrientation("portrait")
...etc...
cordova.plugins.screenorientation.setOrientation("landscape-primary")
cordova.plugins.screenorientation.setOrientation("landscape-secondary")
...etc...

The docs are not very good, but you can figure out what the APIs are by inspecting the files in the www directory in the github repo and by looking for the "clobbers" and "merges" statements inside the plugin.xml file.

Here's a sample of what part of my console debugging session looked like (this plugin fits part of its API into the window.screen object and the rest into window.cordova.plugins, so I was playing with both objects):

Screen Shot 2016-01-04 at 6.33.26 PM.png

0 Kudos
Ozgur_O_
Beginner
1,124 Views

Hi Paul,

Have you tried to rotate your device and did the orientation change?

I'm using the plugin for an iOS App. Maybe there's a bug for the iOS version...

But there's a difference between your code and mine. I used:

window.screen.lockOrientation('landscape-primary'); 

You used :

cordova.plugins.screenorientation.setOrientation("landscape-primary");

Maybe it makes a difference. 

 

0 Kudos
PaulF_IntelCorp
Employee
1,124 Views

When I used the lockOrientation function my device stayed locked. The setOrientation functions do not lock the screen.

There could be a bug in iOS, check the issues link in the github repo, I recall seeing some recent issues posted there, but I don't recall what they were about.
 

0 Kudos
Reply