4

I made a simple application in Intel XDK. When I was testing the application I noticed that they enabled the accelerometer.

For this application it's needed to have only 1 position. How can I disable the accelerometer?

Thanks in advance.

Brad Werth
  • 371
  • 1
  • 10
user3428833
  • 103
  • 1
  • 9

4 Answers4

8

Its not accelerometer that is causing, its the device orientation that needs to fixed.

Call this API to fix the orientation: intel.xdk.device.setRotateOrientation(ORIENTATION); after intel.xdk.device.ready has fired.

Full documentation is here

Portrait: intel.xdk.device.setRotateOrientation("portrait");

Landscape: intel.xdk.device.setRotateOrientation("landscape");

Both: intel.xdk.device.setRotateOrientation("any");

Below is sample code:

<!DOCTYPE html>
<html>
<head>
    <title>XDK</title>
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0;" />

    <script src="intelxdk.js"></script>

    <script>
document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);               
function onDeviceReady(){
    // set orientation
    intel.xdk.device.setRotateOrientation('landscape');
//    intel.xdk.device.setRotateOrientation('portrait');
//    intel.xdk.device.setRotateOrientation('any');

    intel.xdk.device.hideSplashScreen();   
}        
    </script>
    <style>
        body {font-family:arial;background-color:white}
    </style>    
</head>
<body> 
    <h1>Hello World</h1>
    <p>Locked to Landscape</p>
</body>
</html> 
krisrak
  • 12,882
  • 3
  • 32
  • 46
2

That is possible do it the way next:

  1. Go the project properties.
  2. Build Settings
  3. Orientation

You select, landscape or portrait. If you emule the project, you see the changes.

1

use the setRotateOrientation-Method:

To lock the device in portrait mode, use:

intel.xdk.device.setRotateOrientation("portrait");

Works on Android as well as iOS.

See: Documentation

Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
0

Easier is to go to Build Settings -> Your Platform -> Orientation. That very fast and simple.