问题
I want to detect when the phone is locked and unlocked.
The plan is to display a (non-Ad) popup when the phone is unlocked. So far Cordova seems to only support pause and resume events which will not get me the functionality that I need.
Native Android supports screen On/Off and User Present events. Is it possible to use these events and if not is it possible to build a plugin to gain that same functionality?
Thanks in advance.
回答1:
For android you will have to use this plugin template to create a background service so you can listen for those events:
https://github.com/Red-Folder/bgs-sample
On iOS there is a plugin that already implements this functionality if you will eventually deploy on iOS:
https://github.com/ttatarinov/lock-screen-logger-phonegap-plugin
来源:https://stackoverflow.com/questions/33447779/detect-screen-off-on-in-cordova-and-ionic