Detect if user is currently present without receiver for ACTION_USER_PRESENT and ACTION_SCREEN_OFF

你离开我真会死。 提交于 2019-12-11 10:14:20

问题


Is there a way to detect if the user is currently present without listening for the ACTION_USER_PRESENT-event and its counterpart ACTION_SCREEN_OFF?

I don't like to cache the last event in SharedPrefs, because I can't listen for ACTION_SCREEN_OFF using a receiver registered in the manifest. I want to avoid to implement a service that runs all the time just to get the ACTION_SCREEN_OFF-event. Because that service doesn't run anymore if my app crashes.

PowerManager#isScreenOn() or PowerManager#isInteractive() aren't an option since they return true if the user interacts with the lock screen.

Must support API level >=17.

来源:https://stackoverflow.com/questions/35316859/detect-if-user-is-currently-present-without-receiver-for-action-user-present-and

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