3

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();
Davide Lorenzi
  • 348
  • 2
  • 6

1 Answers1

4
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
Ran
  • 4,117
  • 4
  • 44
  • 70
  • Tnx for response.. i've already tried this, but it seems to work only when the device is connected to the pc through the usb cable! There's no other way? – Davide Lorenzi May 23 '12 at 12:49