First, screen and wake-up related knowledge:
1) Kill screen: Press the power button to turn off the screen
2) Wake-up screen: Press the Power key to wake up the screen while in the off-screen state
Second, the screen and screen-related API:
| return value |
Method name |
Describe |
| void |
WakeUp () |
Analog Press the Power key if the screen is awake without any effect |
| void |
Sleep () |
Simulates pressing the Power key if the screen is turned off without any effect |
| Boolean |
Isscreenon () |
Check whether the screen is lit |
Third, API application examples:
Packagecom.uiautomatortest;ImportAndroid.graphics.Point;ImportAndroid.os.Bundle;Importandroid.os.RemoteException;Importandroid.view.KeyEvent;ImportCom.android.uiautomator.core.UiDevice;Importcom.android.uiautomator.testrunner.UiAutomatorTestCase; Public classTestextendsUiautomatortestcase { Public voidTestsleepandwakeup ()throwsremoteexception{if(Uidevice.getinstance (). Isscreenon () = =true) {uidevice.getinstance (). Sleep (); Sleep (2000); Uidevice.getinstance (). WakeUp (); Sleep (2000); //(159,515) (320,515) intStartX, Starty, EndX, EndY, steps; StartX=159; Starty=515; EndX=320; EndY=515; Steps=100; Uidevice.getinstance (). Drag (StartX, Starty, EndX, EndY, steps); } }}Test.java
Android Wireless test-uiautomator Uidevice API Introduction Six