2

How can I turn off my android SmartPhone screen programmatically? I tried with the code below, it doesn't work, it just locks the screen but does not "switch off" the screen.
The method goToSleep have been Removed. https://developer.android.com/sdk/api_diff/21/changes/android.os.PowerManager.html

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
 PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
 wl.acquire();
   ..screen will stay on during this section..
 wl.release();
  • Regarding your edit: have you looked at *all* the answers in the linked post? There are more than 2 methods presented. – sco1 Dec 22 '15 at 11:02

1 Answers1

0

Set permission

<uses-permission android:name="android.permission.WAKE_LOCK">

Here is the code

PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
manager.goToSleep(int amountOfTime);
thestar
  • 4,959
  • 2
  • 28
  • 22
  • The method goToSleep have been Removed. https://developer.android.com/sdk/api_diff/21/changes/android.os.PowerManager.html – Uihrguhg Shdg Dec 22 '15 at 10:08