简体   繁体   中英

Run Windows Phone 8.1 RT app under lockscreen

How can I make my Windows Phone 8.1 app continue to run under the lockscreen like I can in Windows Phone 8 using the following code:

        PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
        PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame;
        if (rootFrame != null)
        {
            rootFrame.Obscured += new EventHandler<ObscuredEventArgs>(rootFrame_Obscured);
            rootFrame.Unobscured += new EventHandler(rootFrame_Unobscured);
        }

I am working on a Windows Phone 8.1 runtime (store) app as in not the Silverlight type one so for a start it seems that PhoneApplicationService is not part of this API so the above code will not work. Does anyone have an idea what the recommended way of doing this in Windows Phone 8.1 is?

PS. If this is not possible as I am beginning to dread is the case, what are my alternative options?

UPDATED

When building RT Windows Phone 8.1 apps, PhoneApplicationService is no longer available (only available for Silverlight Windows Phone 8.1 apps).

At this point, it doesn't look like there is a direct replacement but there are workarounds being performed using the DisplayRequest class.

OLD

If you double check the documentation for PhoneApplicationService , you'll notice that it is still supported in Windows Phone 8.1.

I'm guessing that you're building a Universal App and that you're trying to put this code into part of the Shared Project that is used by both the Windows 8.1 and the Windows Phone 8.1 project.

In that case, you'll need to use the supported Preprocessor directives to specify platform specific sections of your code:

#if WINDOWS_PHONE_APP

PhoneApplicationService.Current.ApplicationIdleDetectionMode = 
    IdleDetectionMode.Disabled;
// etc.

#endif

You can read more about how to share different bits of code in Universal Applications at:

How to share code among different Universal Windows apps (which discusses the above method towards the bottom of the article)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM