Wake up Android with use adb or Eclipse (just befo

2019-01-31 13:02发布

How to wake up Android with use adb - I want to wake up (if asleep) Android terminal before debugging every new version of application.

Typical flow is: 1. I do some changes in Eclipse. 2. In the meantime screen goes off or not. 3. I run "debug" and want force screen to wake up.

I found a method with "power key" emulation but it does not turn it on but rather toggles the power state. I do not want to add extra code to my application. What are the other methods to do such trivial task, please help.

9条回答
何必那么认真
2楼-- · 2019-01-31 13:19

Just use :

adb shell input keyevent 26
查看更多
Emotional °昔
3楼-- · 2019-01-31 13:20

You can check device's current power state (including display) via adb with dumpsys power command and send the power key press event only if the display is off. The easier solution would be disabling the display timeout altogether "while connected to USB" in the Developer options.

查看更多
Lonely孤独者°
4楼-- · 2019-01-31 13:26

you could also add the following flags to your onCreate() in your main activity:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

This way your device should wake up when it is loaded onto the device through Eclipse.

查看更多
狗以群分
5楼-- · 2019-01-31 13:26

if you execute adb shell input keyevent KEYCODE_POWER and got Killed, you should use root user by execute su before.

sleep:(adb shell) input keyevent KEYCODE_SLEEP

wakeup:(adb shell) input keyevent KEYCODE_WAKEUP

toggle:(adb shell) input keyevent KEYCODE_POWER

查看更多
我想做一个坏孩纸
6楼-- · 2019-01-31 13:28

I used the following to wake up remote devices for automated tests. If the screen isn't on, then it will press the power button followed by the menu button.

(
  cd ${platform-tools};
  ./adb shell dumpsys power | grep -i 'SCREEN_ON' >/dev/null;
  if [ $? -eq 0 ]; then
    echo "Screen is on...";
  else
    echo "Pressing buttons to wake-up...";
    # http://developer.android.com/reference/android/view/KeyEvent.html
    ./adb shell input keyevent 26; # Power
    ./adb shell input keyevent 82; # Menu
    echo "Pausing for state to settle...";
    sleep 1;
    ./adb shell dumpsys power | grep -i 'SCREEN_ON';
  fi;
  echo '---';
  ./adb shell dumpsys power | grep -i 'SCREEN'
)
查看更多
7楼-- · 2019-01-31 13:29

For Windows and Eclipse you can use .bat file:

@ECHO OFF
setlocal
for /f "delims= tokens=1*" %%a in ('adb shell dumpsys power ^| findstr.exe "mScreenOn="') DO (
for /f "delims== tokens=2*" %%S in ("%%a") do (
if "%%S" == "false" (goto move1) else (goto move2)
)
)

:move1
adb shell input keyevent 26
goto end

:move2
goto end

:end
exit

It will check, if screen is off it will switch the power state. To use it with Eclipse this .bat file should be used as "External tool" (just fill the path to the .bat) and linked to the project in it's properties (Builders - Import - ).

查看更多
登录 后发表回答