BackgroundExecutionManager.RequestAccessAsync | requestAccessAsync methods

Applies to Windows and Windows Phone

On Windows, this method presents the user with a dialog box that requests that an app be added to the lock screen. On Windows Phone, this method does not prompt the user, but must be called before registering any background tasks. Due to this difference in behavior, the values returned by this method have different meanings depending on which type of app is calling it.

Overload list

MethodDescription
RequestAccessAsync() On Windows, this method presents the user with a dialog box that requests that an app be added to the lock screen. On Windows Phone, this method does not prompt the user, but must be called before registering any background tasks.
RequestAccessAsync(String) On Windows, this method presents the user with a dialog box that requests that an app be added to the lock screen. On Windows Phone, this method does not prompt the user, but must be called before registering any background tasks.

Remarks

This method must be called from the UI thread. If it is not called from the UI thread, in some cases you can see error code 0x80070490 (ERROR_NOT_FOUND) in place of 0x80070005 (E_ACCESSDENIED). Receipt of error code 0x80070490 is a good indication that you are not calling from the UI thread.

Examples

This example shows this method used to add an app to the lock screen.


var Background = Windows.ApplicationModel.Background;

var promise = Background.BackgroundExecutionManager.requestAccessAsync().then(
    function(result) {
        switch (result) {
            case Background.BackgroundAccessStatus.denied:
                // Windows: Background activity and updates for this app are disabled by the user.
                //
                // Windows Phone: The maximum number of background apps allowed across the system has been reached or
                // background activity and updates for this app are disabled by the user.
                break;
    
            case Background.BackgroundAccessStatus.allowedWithAlwaysOnRealTimeConnectivity:
                // Windows: Added to list of background apps; set up background tasks; 
                // can use the network connectivity broker.
                //
                // Windows Phone: This value is never used on Windows Phone.
                break;
    
            case Background.BackgroundAccessStatus.allowedMayUseActiveRealTimeConnectivity:
                // Windows: Added to list of background apps; set up background tasks;
                // cannot use the network connectivity broker.
                //
                // Windows Phone: This app can register background tasks. Required for all 
                // background tasks on Windows Phone.
                break;
    
            case Background.BackgroundAccessStatus.unspecified:
                // The user didn't explicitly disable or enable access and updates. 
                break;
        }
    });

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

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

See also

BackgroundExecutionManager

 

 

Show:
© 2014 Microsoft