Android OS2.2 used to have an option under Settings/Applications/Development to disable screen lock during USB debugging. After upgrading my Samsung Galaxy S to OS2.3.3 this
I have Android version 2.3.6 and under settings
-> applications
-> development
there is an option to stay awake (i.e. your screen will never sleep) while it is plugged in to charge.
Jorge Cevallos is right.
For Android 4 and higher :
Have fun.
Two options come into my mind:
write an app which will force screen timeout to be very high. Use SCREEN_OFF_TIMEOUT or STAY_ON_WHILE_PLUGGED_IN
.
If your phone is rooted and you are connected to wifi in the same network as the computer you're developing on, you can enjoy this wonderful app which comes with an option for screen timeout too: wifi adb.
On console
while true; do adb shell input keyevent mouse ; sleep 1 ; done
I have created an app for this purpose. You can search it on google play "Keep Awake for Debugging" .It will keep your phone-unlocked/screen-on only when you have ADB debugging enabled. It is not restricted to USB only, it works over wi-fi as well.
Simple. Just add the following code to your activity, and your screen will turn on ONLY when you debug:
@Override
protected void onResume()
{
Log.d( tag, "onResume()" );
try
{
super.onResume();
if( BuildConfig.DEBUG && Debug.isDebuggerConnected() )
{
Log.d("SCREEN", "Keeping screen on for debugging, detach debugger and force an onResume to turn it off.");
getWindow().addFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON );
}
else
{
getWindow().clearFlags( WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON );
Log.d( "SCREEN", "Keeping screen on for debugging is now deactivated.");
}
}
catch( Throwable t )
{
Log.e( tag, "onResume() - Exception: " + t.getMessage(), t );
}
}