How do I keep my screen unlocked during USB debugging?

前端 未结 19 1302
清酒与你
清酒与你 2020-12-13 07:55

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

相关标签:
19条回答
  • 2020-12-13 08:33

    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.

    0 讨论(0)
  • 2020-12-13 08:34

    Jorge Cevallos is right.

    For Android 4 and higher :

    1. Go to Settings > About phone
    2. Touch several times (about 10 times) on "Build number".
    3. Then go back to Sttings menu and you'll find the "Developer options"
    4. Under "Developer Options", you will see "stay awake option ".

    Have fun.

    0 讨论(0)
  • 2020-12-13 08:38

    Two options come into my mind:

    1. write an app which will force screen timeout to be very high. Use SCREEN_OFF_TIMEOUT or STAY_ON_WHILE_PLUGGED_IN.

    2. 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.

    0 讨论(0)
  • 2020-12-13 08:39

    On console

     while true; do adb shell input keyevent mouse ; sleep 1 ; done
    
    0 讨论(0)
  • 2020-12-13 08:40

    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.

    0 讨论(0)
  • 2020-12-13 08:40

    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 );
        }
    }
    
    0 讨论(0)
提交回复
热议问题