Android Question How to determine in the service module that the phone is switched off?

I am creating an application that runs in the background. I need to determine in the service module: is the phone turned on at the moment?
Of course, I can determine, with PhoneEvents, when the phone turns on - the ScreenOn event, or when it turns off - the ScreenOff event. And thus determine the state of the phone.
But I would like, when the timer is triggered, to determine: is the phone turned on at this moment?
I have looked closely at the Phone library and have not found a suitable property for this object.
Very grateful in advance.
You must have a foreground service for this.
Background location tracking

Handle the ScreenOn/Off events and store the state in a global variable. You can then check it with a timer.
Thank you, Mr. Erel!
To be honest, then at the moment I do this. Simply, I thought it was possible to determine the status of the phone directly, without tracking the SCREENON / OFF events.
Well, it means that I will continue to do this.
Thank you again, you confirmed the correctness of my choice.
Upvote 0