How to capture unlock screen event in Window phone

2019-07-07 07:40发布

How to capture Screen unlock event and then fire some event from my app when screen is unlocked in Window phone 7.1?

1条回答
地球回转人心会变
2楼-- · 2019-07-07 08:11

You can handle the PhoneApplicationFrame.Unobscured event. The only problem is that this event will fire when other types of chrome is removed (such as a MessageBox being closed).

However, you could keep track of a variable that checks if the Activated event has been fired as that event is raised when the phone is unlocked.

So in your Unobscured event, check if the flag in the Activated event is set to true and you can then assume, with relatively high confidence, that the user has unlocked their phone. (This is untested but it seems like it would work).

From MSDN:

In an ordinary app, the following events occur.

  • When the phone is locked, first the Obscured event is raised, and then the Deactivated event is raised. You can check the IsLocked property of the ObscuredEventArgs to determine whether the lock screen caused the deactivation.

  • When the phone is unlocked, the Activated event is raised, and then the Unobscured event is raised.

In an app that use location services and that is specially configured to run continuously in the background, the following events occur.

  • When the phone is locked, the Obscured event is raised. You can check the IsLocked property of the ObscuredEventArgs to determine whether the lock screen obscured the app.

  • When the phone is unlocked, the Unobscured event is raised.

查看更多
登录 后发表回答