2

Is there a way to sleep android phone for 10 seconds and wake it up automatically?

Other details: I have SU access to the device and these devices have android version above 4.4

jay
  • 1,982
  • 2
  • 24
  • 54

1 Answers1

1

try this

     private PowerManager powerManager;
     private PowerManager.WakeLock wakeLock;

     public void turnOnScreen(){
         // turn on screen
         Log.v("MyActivity", "ON!");
         wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
         wakeLock.acquire();
    }

     @TargetApi(21) //Suppress lint error for PROXIMITY_SCREEN_OFF_WAKE_LOCK
     public void turnOffScreen(){
         // turn off screen
         Log.v("MyActivity", "OFF!");
         wakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
        // start a timer to count when its done call turnOnScreen
         wakeLock.acquire();
    }

also in manifest <uses-permission android:name="android.permission.WAKE_LOCK" />

Charuක
  • 12,953
  • 5
  • 50
  • 88
  • Is there a way for Android 4.4 (API level 19)? – jay Dec 17 '16 at 08:26
  • yes try this ,, but its not turn off its dim at its top --> WindowManager.LayoutParams params = this.getWindow().getAttributes(); /**Seems Like Turn off: */ params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; //TODO Store original brightness value params.screenBrightness = 0.1f; this.getWindow().setAttributes(params); //to show it wakes up again use params.screenBrightness = 0.9f; – Charuක Dec 17 '16 at 08:31
  • your solution does not seem to work (I have tried with Android 5.1) – jay Dec 17 '16 at 08:36
  • aaa then try one of these options and see http://stackoverflow.com/questions/9561320/android-how-to-turn-screen-on-and-off-programmatically – Charuක Dec 17 '16 at 08:43