Detect Screen Off / On in Cordova and Ionic

自古美人都是妖i 提交于 2020-01-02 05:31:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!