6

I am developing Android app with my daily phone, I want to turn off screen lock only during development.

I can do this manually, but that is too troublesome and sometimes I forget to enable it back after development.

Are there ways to do this automatically? i.e. turn off screen lock when connected to USB?

4 Answers 4

14

There are other ways too. My favorite is:

$ adb shell svc power stayon true

See here: https://stackoverflow.com/questions/8840954/how-do-i-keep-my-screen-unlocked-during-usb-debugging

1
  • 1
    This command will keep the device on not only for USB but also for Wireless or AC adapter charging.
    – krishna
    Commented Feb 15, 2017 at 5:24
7

Yes. Go to Settings -> Developer options and turn on the Stay awake option.

0

So I faced this problem too and I got quite annoyed at having to go into settings and enable "stay awake" and then disable it when I'm done. Searching the Play Store for an app to do it autonomously, and tried a few that claimed to work but didn't, so I made my own...

And the code is available open-source here: https://github.com/projectdelta6/ADB-Stay-Awake#adb-stay-awake

0

I created simple shell script for my macOS

File Name : cell-screen.sh

#!/bin/sh

echo '`cell-screen on` to keep the screen on during usb debugging'
echo '`cell-screen off` to reset'

echo ''
echo 'your parameter - ' $1

if [[ "$1" = "on" ]]; then
    ~/Library/Android/sdk/platform-tools/adb shell settings put global stay_on_while_plugged_in 2
elif [[ "$1" = "off" ]]; then
    ~/Library/Android/sdk/platform-tools/adb shell settings put global stay_on_while_plugged_in 0
else
    echo '\n[****]Bad Input.'
fi

echo '\nEnd'

Steps:

  1. I saved the script to the default use location - /Users/[your username]
  2. Given executable access to the file - chmod +x ~/cell-screen.sh
  3. Whenever I start my development tasks, I just execute the shell script in terminal - ~/cell-screen.sh on
  4. After I complete my development work, I simply execute - ~/cell-screen.sh off

For Windows Users:

Change the shell script for the adb location - %LOCALAPPDATA%\Android\sdk\platform-tools\adb

1
  • Where are the values 0 and 2 documented? I have found these values but I'm not sure how to convert those to integers. Is it by bitmask? If so, are the values listed 1,2,4,8 in the order they are listed? If so, then where is that documented? Thank you.
    – dotancohen
    Commented Jul 7 at 12:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .