4

How to turn off screen of android phone programmatically? I tried using following code with no luck

PowerManager mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MYTAG");

mWakeLock.acquire();
Uri Agassi
  • 36,848
  • 14
  • 76
  • 93
user3480011
  • 41
  • 1
  • 2
  • 1
    I'm not sure why you expected that aquiring a partial wakelock would turn the screen off(?) The documentation for `PARTIAL_WAKE_LOCK` even says _"Ensures that the CPU is running; the screen and keyboard backlight will be allowed to go off"_. "Will be allowed to" does not mean the same thing as "Will". – Michael Mar 31 '14 at 06:38
  • will setting brightness to zero work. I wonder. http://stackoverflow.com/questions/3737579/changing-screen-brightness-programmatically-in-android – rahulroy9202 Mar 31 '14 at 07:02
  • http://stackoverflow.com/questions/6756768/turn-off-screen-on-android/6757206#6757206 Check this answer. – rahulroy9202 Mar 31 '14 at 07:04
  • @rahulroy9202 setting brightness to 0 will dim the screen to its lowest values, it won't turning it off – Muhammed Refaat Aug 03 '16 at 09:27
  • @user3480011 reached something ?!! – Muhammed Refaat Aug 03 '16 at 09:27

0 Answers0