Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find if phone is in standby mode? (Screen is off, power button pressed)

As title says, i need to get this information regarding the screen state.

I think stanby is the correct state i mean, that is when you press the power button and the screen turn off completely.

But how to detect this?

Tnx in advance for your help.

SOLVED:

I managed to solve the problem i was having: the code was right, but the thread was stopping executing when in stanby mode; that's because i was having the wrong feeling that the code was wrong. Solved simply by using a wake lock, that ensure the cpu will be active even when in stanby mode:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
 PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
 wl.acquire();
   ..CPU will stay on during this section..
 wl.release();
like image 556
Davide Lorenzi Avatar asked Jan 29 '26 12:01

Davide Lorenzi


1 Answers

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
like image 122
Ran Avatar answered Jan 31 '26 01:01

Ran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!