Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SimpleOrientationSensor.GetCurrentOrientation | getCurrentOrientation method

Gets the default simple orientation sensor.

Syntax


var simpleOrientation = simpleOrientationSensor.getCurrentOrientation();

Parameters

This method has no parameters.

Return value

Type: SimpleOrientation

The default simple orientation sensor.

Remarks

An application may use this method to poll the sensor for the current reading as an alternative to registering a OrientationChanged event handler. This would be the preferred alternative for an application that updates its user interface at a specific frame rate.


private void ScenarioGet(object sender, RoutedEventArgs e)
{
    if (_sensor != null)
    {
        DisplayOrientation(ScenarioOutput_Orientation, _sensor.GetCurrentOrientation());
    }
    else
    {
        rootPage.NotifyUser("No simple orientation sensor found", NotifyType.StatusMessage);
    }
}


The following example demonstrates how a Windows Store app built for Windows using JavaScript retrieved the current device orientation by using the simple orientation sensor.


function invokeGetReadingScenario() {
    if (sensor) {
        var orientation = sensor.getCurrentOrientation();

        switch (orientation) {
            case Windows.Devices.Sensors.SimpleOrientation.notRotated:
                document.getElementById("readingOutputOrientation").innerHTML = "Not Rotated";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.rotated90DegreesCounterclockwise:
                document.getElementById("readingOutputOrientation").innerHTML = "Rotated 90";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.rotated180DegreesCounterclockwise:
                document.getElementById("readingOutputOrientation").innerHTML = "Rotated 180";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.rotated270DegreesCounterclockwise:
                document.getElementById("readingOutputOrientation").innerHTML = "Rotated 270";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.faceup:
                document.getElementById("readingOutputOrientation").innerHTML = "Face Up";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.facedown:
                document.getElementById("readingOutputOrientation").innerHTML = "Face Down";
                break;
            default:
                document.getElementById("readingOutputOrientation").innerHTML = "Undefined orientation " + orientation;
                break;
        }
    } else {
        WinJS.log && WinJS.log("No simple orientation sensor found", "sample", "error");
    }
}


Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Devices.Sensors
Windows::Devices::Sensors [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

Minimum supported client

Windows 8

Minimum supported server

None supported

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Devices.Sensors
Windows::Devices::Sensors [C++]

Metadata

Windows.winmd

See also

SimpleOrientationSensor

 

 

Show:
© 2015 Microsoft