Is it possible to create such a Service , which in the background will determine whether the user has the phone screen turned on or not (is the lock screen turned on)?
|
1 answer
You can create a service that monitors the on / off screen by receiving the broadcast event ACTION_SCREEN_OFF
An example can be found here , for example.
- thank. and planned to do. I need to calculate the time how much the phone is turned off. I think before the phone goes to sleep, take the current date and time in milliseconds, then when turned on, take the date and calculate the difference. - Firespirit
- In addition, the status of the display can be found at any time using the getState () method of the Display class. developer.android.com/reference/android/view/… - AseN
- in my opinion, only with 20api getState will work - Firespirit
- Yes, that's right, the getState () method was added at 20 Api Level. Well, if this is unacceptable (and this is most likely the case), then the option disappears. - AseN
- everything works well for me out of activation, but for some reason I can’t make the receiver continue to work after closing the activation - Firespirit
|