DeviceUseTrigger
DeviceUseTrigger
DeviceUseTrigger
DeviceUseTrigger
Class
Definition
Represents an event that a Windows Runtime app can trigger to initiate a long-running operation with a device or sensor.
DeviceUseTrigger lets your Windows Runtime app access sensors and peripheral devices in the background, even when your foreground app is suspended. For example, depending on where your app is running, it could use a background task to synchronize data with devices or monitor sensors.
This class can be used in Windows Store app and Windows Phone Store app. However, a DeviceUseTrigger background task supports different APIs, and is subject to different policies, depending where it's running (PC or phone). To learn more about these differences, see Accessing sensors and devices from a background task.
Important
This trigger cannot be used with single-process background tasks.
For a sample that shows how to use DeviceUseTrigger on a PC, see the Custom USB device sample. For a phone sample, see the Background Sensors sample.
public : sealed class DeviceUseTrigger : IBackgroundTrigger, IDeviceUseTriggerpublic sealed class DeviceUseTrigger : IBackgroundTrigger, IDeviceUseTriggerPublic NotInheritable Class DeviceUseTrigger Implements IBackgroundTrigger, IDeviceUseTrigger// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Remarks
For more about policy requirements, see Accessing sensors and devices from a background task
Before your app triggers a background task on a phone, it must first call RequestAccessAsync to check if the app is able to request a background task. This check is not required when your app is running on a PC.
Constructors
DeviceUseTrigger() DeviceUseTrigger() DeviceUseTrigger() DeviceUseTrigger()
Constructor for DeviceUseTrigger. Takes no parameters.
public : DeviceUseTrigger()public DeviceUseTrigger()Public Sub New()// You can use this method in JavaScript.
Methods
RequestAsync(String) RequestAsync(String) RequestAsync(String) RequestAsync(String)
Triggers the background task and returns a DeviceTriggerResult indicating success or failure of the trigger request. Takes the DeviceInformation.ID of the device or sensor that the background task will access.
public : IAsyncOperation<DeviceTriggerResult> RequestAsync(PlatForm::String deviceId)public IAsyncOperation<DeviceTriggerResult> RequestAsync(String deviceId)Public Function RequestAsync(deviceId As String) As IAsyncOperation( Of DeviceTriggerResult )// You can use this method in JavaScript.
- deviceId
- PlatForm::String String String String
The DeviceInformation.ID of the device or sensor that the background task will access. It must match the device or sensor that will perform the background operation. It is used by Windows to ensure that policy requirements are met.
This method returns a DeviceTriggerResult when it completes asynchronously.
- See Also
RequestAsync(String, String) RequestAsync(String, String) RequestAsync(String, String) RequestAsync(String, String)
Triggers the background task and returns a DeviceTriggerResult indicating success or failure of the trigger request. Takes the DeviceInformation.ID of the device or sensor that the background task will access, and an optional app-specific string passed to the background task identifying which operation to perform.
public : IAsyncOperation<DeviceTriggerResult> RequestAsync(PlatForm::String deviceId, PlatForm::String arguments)public IAsyncOperation<DeviceTriggerResult> RequestAsync(String deviceId, String arguments)Public Function RequestAsync(deviceId As String, arguments As String) As IAsyncOperation( Of DeviceTriggerResult )// You can use this method in JavaScript.
- deviceId
- PlatForm::String String String String
The DeviceInformation.ID of the device or sensor that the background task will access. It must match the device or sensor that will perform the background operation. It is used by Windows to ensure that policy requirements are met.
- arguments
- PlatForm::String String String String
Optional value. A string specified by your app and passed to the background task, identifying which operation to perform.
This method returns a DeviceTriggerResult when it completes asynchronously.
- See Also