Windows Dev Center

EN
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

BackgroundExecutionManager class

Provides methods that let an app ask to be added to the lock screen's apps list or query its current access to background activity and badge updates on the lock screen.

Syntax


var backgroundExecutionManager = Windows.ApplicationModel.Background.BackgroundExecutionManager;

Members

The BackgroundExecutionManager class has these types of members:

Methods

The BackgroundExecutionManager class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
GetAccessStatus Gets the ability of the calling lock screen app to perform background activity and update its badge.
GetAccessStatus(String) Gets the ability of a specific lock screen app to perform background activity and update its badge.
RemoveAccess Removes the calling app from the lock screen's apps list.
RemoveAccess(String) Removes a specific app from the lock screen's apps list.
RequestAccessAsync Requests access for an app to run background tasks.
RequestAccessAsync(String) Requests access for an app to run background tasks.

 

Remarks

Because apps with a presence on the lock screen are allowed to run some tasks in the background, certain classes of apps will require the access gained through this class in order to execute their core scenarios.

For a full sample demonstrating the use of this class, see the Lock Screen Sample on the Windows Dev Center.

Examples

This example shows the use of this class to add an app to the lock screen and grant it the ability to perform background tasks.


var Background = Windows.ApplicationModel.Background;

var promise = Background.BackgroundExecutionManager.requestAccessAsync().then(
    function(result) {
        switch (result) {
        case Background.BackgroundAccessStatus.denied:
            // Disabled by the user. 
            break;

        case Background.BackgroundAccessStatus.allowedWithAlwaysOnRealTimeConnectivity:
            // Added to list of background apps.
            // Set up background tasks; can use the network connectivity broker.
            break;

        case Background.BackgroundAccessStatus.allowedMayUseActiveRealTimeConnectivity:
            // Added to list of background apps.
            // Set up background tasks; cannot use the network connectivity broker.
            break;

        case Background.BackgroundAccessStatus.unspecified:
            // The user didn't explicitly disable or enable. 
            break;
        }
    });

Removing an app from the lock screen.


var Background = Windows.ApplicationModel.Background;
Background.BackgroundExecutionManager.removeAccess();

This example shows how to query for an app's lock screen state.


var Background = Windows.ApplicationModel.Background;

var result = Background.BackgroundApplications.getAccessStatus();
switch (result) {
case Background.BackgroundAccessStatus.denied:
    // Disabled by the user.
    // Cannot display on the lock screen or set up background tasks.
    break;

case Background.BackgroundAccessStatus.allowedWithAlwaysOnRealTimeConnectivity:
    // Added to list of background applications.
    // Can display on the lock screen.
    // Can set up background tasks and use the network connectivity broker.
    break;

case Background.BackgroundAccessStatus.allowedMayUseActiveRealTimeConnectivity:
    // Added to list of background applications.
    // Can display on the lock screen.
    // Can set up background tasks but cannot use the network connectivity broker.
    break;

case Background.BackgroundAccessStatus.unspecified:
    // The user didn't explicitly disable or enable.
    break;
}

Requirements (Windows 10 device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.ApplicationModel.Background
Windows::ApplicationModel::Background [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

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

Namespace

Windows.ApplicationModel.Background
Windows::ApplicationModel::Background [C++]

Metadata

Windows.winmd

Attributes

[Version(0x06020000)]

See also

Object
Lock screen apps sample

 

 

Mostrar:
© 2015 Microsoft