Skip to content

[WASM] Accelerometer is available even with no sensors in the device #11598

@morning4coffe-dev

Description

@morning4coffe-dev

Current behavior

Although there is no accelerometer sensor in my desktop device, the Accelerometer.GetDefault(); still returns some Accelerometer with empty values.

image

Sensor tester on the same device:

image

Expected behavior

The Accelerometer.GetDefault(); should return null.

How to reproduce it (as minimally and precisely as possible)

var accelerometer = Accelerometer.GetDefault();
			
if (accelerometer != null)
{
	accelerometer.ReadingChanged += Accelerometer_ReadingChanged;
}
else
{
	// Accelerometer is not available on this platform/device.
}

private void Accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
	LastReadTimestamp = args.Reading.Timestamp;
	AccelerationX = args.Reading.AccelerationX;
	AccelerationY = args.Reading.AccelerationY;
	AccelerationZ = args.Reading.AccelerationZ;
}

Workaround

No response

Works on UWP/WinUI

Yes

Environment

No response

NuGet package version(s)

No response

Affected platforms

WebAssembly

IDE

Visual Studio 2022

Anything else we need to know?

In TypeScript there is some new method for getting the sensor, so maybe that could be a solution.

Metadata

Metadata

Assignees

Labels

difficulty/starter 🚀Categorizes an issue for which the difficulty level is reachable by newcomerskind/bugSomething isn't workingproject/non-ui ⚙️Categorizes an issue or PR as relevant to winrt (non-ui)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions