Accessing pedometer in UWP app

284 views Asked by At

Here's pedometer sample for UWP. It works fine on my phone.

However, in my custom app, I cannot get it to determine whether the pedometer device can be accessed. It always gives me DeviceAccessStatus.Unspecified status.

Here's the standard code:

// Common class ID for pedometers
Guid PedometerClassId = new Guid("B19F89AF-E3EB-444B-8DEA-202575A71599"); 

// Determine if we can access pedometers
var deviceAccessInfo = DeviceAccessInformation.CreateFromDeviceClassId(PedometerClassId);
if (deviceAccessInfo.CurrentStatus == DeviceAccessStatus.Allowed)
{}

What I may be missing here, guys? Same happens on device that supports Pedometer and on one that doesn't.

I've compared both project manifest files, etc.

If I skip this check, then later on I get Access denied exception when trying to run viewModel.Pedometer = await Pedometer.GetDefaultAsync();.

1

There are 1 answers

3
Martin Zikmund On BEST ANSWER

Have you specified the Device capability in the Package.appxmanifest?

<Capabilities>
   <DeviceCapability Name="activity" />
</Capabilities>

It is present in the sample's manifest (line 58), it is probably required to be able to access the device. The AccessDeniedException seems to support this.