简体   繁体   English

在Cordova和Ionic中检测屏幕关/开

[英]Detect Screen Off / On in Cordova and Ionic

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. 到目前为止,Cordova似乎只支持暂停和恢复事件,这些事件不会让我获得我需要的功能。

Native Android supports screen On/Off and User Present events. Native Android支持屏幕On / Off和User Present事件。 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. 提前致谢。

For android you will have to use this plugin template to create a background service so you can listen for those events: 对于Android,您必须使用此插件模板来创建后台服务,以便您可以监听这些事件:

https://github.com/Red-Folder/bgs-sample 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: 在iOS上有一个插件,如果你最终将在iOS上部署,它已经实现了这个功能:

https://github.com/ttatarinov/lock-screen-logger-phonegap-plugin https://github.com/ttatarinov/lock-screen-logger-phonegap-plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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