如何在USB调试期间保持屏幕解锁?

时间:2023-01-13 21:47:12

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 option disappeared and it's VERY frustrating to keep unlocking my phone while debugging.

Android OS2.2在设置/应用程序/开发中有一个选项,可以在USB调试期间禁用屏幕锁。在升级我的三星Galaxy S到OS2.3.3后,这个选项消失了,在调试过程中不断解锁我的手机是非常令人沮丧的。

Has this option moved or is there another way to do it? (I hate when useful options are removed for no reason!)

这个选项移动了吗?或者还有别的方法吗?(我讨厌无缘无故地删除有用的选项!)

Thanks in advance...

提前谢谢…

15 个解决方案

#1


32  

There are multiple options, many of which have HORRIBLE (subjective) side effects. I'll list what I've found and what side effects I could think of.

有多种选择,其中许多有可怕的(主观的)副作用。我会列出我发现的以及我能想到的副作用。

I'm lazy, possibly like many others, and I don't like to keep on eye out for something unneccessarily. This means that the "Oh, I'll just turn this on while I'm working and then turn it off when finished" option is not a viable one. You will forget it and you will experience any of the sideeffects listed below eventually.

我很懒,可能和其他很多人一样,我不喜欢盯着不需要的东西。这意味着“哦,我在工作的时候打开它,然后在完成时关闭它”选项不是可行的。你会忘记它,最终你会体验到下面列出的任何副作用。

TL;DR

FLAG_KEEP_SCREEN_ON with a Debug.isDebuggerConnected() guard FTW! Stay awake when charging, Screen timeout and wake-lock are non-viable options if you just want to debug.
There's also an advantage of this solution working from API 1 AND wifi debugging!

使用Debug.isDebuggerConnected()保护FTW!如果您只是想调试的话,充电、屏幕超时和wake-lock都是不可行的选项。在API 1和wifi调试中也有这个解决方案的优势!

Settings > Developer Options > Stay awake when charging

Burn in: There should be a huge red flag anyone turning this on. It says "while charging" not "while debugging". Which means that even if your phone is plugged in to the mains it will keep on. This is especially bad if you have an AMOLED screen (e.g. Galaxy S series) which burns stuff in. I had this option on for a few weeks and now I have a permanent portrait status bar...

燃烧:应该有一个巨大的红旗谁打开这个。它说“充电时”而不是“调试时”。这意味着,即使你的手机接通电源,它也会继续。如果你有一个AMOLED屏幕(比如Galaxy S系列),它会把东西烧进去,那就更糟糕了。我有这个选择几个星期,现在我有一个永久肖像状态栏……

Notifications: Even if you use low brightness and don't forget to turn your screen off every time you put the phone down some apps wake your screen up if you get just a simple notification which leads to keeping it on most of the time while plugged in.

通知:即使你使用的是低亮度的屏幕,也不要忘记在你每次放下手机的时候关掉一些应用程序,如果你只收到一个简单的通知,那么你的屏幕就会被唤醒,这将导致你在大部分时间都处于开机状态。

Security: If you just leave your screen on while charging and you're needed quickly for something at work, the first thing won't be "Ah, let me lock my phone first" and you may expose your dirty secrets if you accidentally left it on. Let me note that if you're working in an environment where you can't trust your collegaues, I would reconsider that employment.

安全性:如果你在充电的时候只打开你的屏幕,而且你在工作中很快就需要一些东西,那么第一件事不会是“啊,让我先把手机锁上”,如果你不小心把手机开着,你可能会暴露你的脏秘密。我要指出的是,如果你在一个不能信任你的大学毕业生的环境中工作,我会重新考虑这份工作。

Settings > Display > Screen Timeout

This is very risky if you have lot of apps that give you notifications. Especially if you have some spammers (Facebook, Family Guy or even GMail if you get a lot of mails).

如果你有很多给你通知的应用,这是非常危险的。特别是如果你有一些垃圾邮件发送者(Facebook, Family Guy,甚至GMail,如果你收到很多邮件)。

Burn in: The risk is high with this as well. Now you don't even restrict it to "being on the wire" so it will just stay on whenever you forget to turn it off explicity or get a notification.

消耗:风险也很高。现在你甚至不把它限制在“在电线上”,所以只要你忘记关闭它,它就会继续运行,或者得到通知。

Battery drain: If you get one the screen will be on for the specified amount of time, draining your battery. And it will be on because sometimes you forget to turn it off, or just get a notification.

电池消耗:如果你得到一个屏幕将在指定的时间内打开,耗尽你的电池。它会打开,因为有时候你忘记关掉它,或者只是得到一个通知。

Hotpocket: if you get a notification while the phone is in your pocket the illumination from the screen and the confined space will heat your pockets and you may even get burned.

Hotpocket:如果你在口袋里的时候收到通知,屏幕上的照明和有限的空间会让你的口袋变热,你甚至会被烧伤。

Pocket dial: if your screen turns on while the phone is in your pocket the risk of a pocket dial with increase with every second. Nowadays this is less likely though, because the Phone app is usually well hidden, but my pocket likes to change the date very often or read my emails.

口袋拨号:如果你的屏幕在你的口袋里打开,口袋拨号的风险随着每一秒的增加而增加。现在,这种情况不太可能发生,因为手机应用程序通常都很隐蔽,但我的口袋喜欢经常更改日期或阅读我的电子邮件。

Security: imagine you're in a public place and your phone is on the table, your friends will most likely abuse your unlocked screen if you turn around for long enough to talk to someone or take a quick break. Especially if they're inebriated. Obviously shorter timeouts decrease this risk.

安全性:假设你在一个公共场所,你的手机放在桌子上,如果你长时间地转过头去和别人交谈或短暂休息,你的朋友很可能会滥用你的解锁屏幕。尤其是如果他们喝醉了。显然,更短的超时时间可以降低这种风险。

Using a wake-lock

Permission: You'll need to add a possibly unnecessary android.permission.WAKE_LOCK permission to your app (luckily should be easy to add for only debug variants thanks to Manifest Merger in the Gradle Plugin).

允许:您需要添加一个可能不必要的android.permission。WAKE_LOCK权限到您的应用程序(幸运的是,由于在Gradle插件中明显的合并,应该很容易添加调试变体)。

Coding: You'll also need to manage releasing the lock yourself and maybe need to create a Service just for this. I'd like to note here that I've yet to use this feature in Android.

编码:您还需要自己管理释放锁,可能需要为此创建一个服务。我想在这里指出,我还没有在Android中使用这个功能。

Useless: It also doesn't really help to keep the screen on, since it only keeps the CPU awake. See documentation.

无用:它也不能真正帮助保持屏幕打开,因为它只保持CPU清醒。见文档。

FLAG_KEEP_SCREEN_ON while a Debugger is attached

If you read the documentation for this one, you'll find a very close approximation to your problem.

如果您阅读了这篇文章的文档,您会发现与您的问题非常接近的地方。

Coding: to only downside I can think of here is that you need to modify some code, but it's extremely simple (assuming you have a BaseActivity that all your other activities extend):

编码:我认为唯一的缺点是您需要修改一些代码,但是它非常简单(假设您有一个所有其他活动都扩展的BaseActivity):

@Override protected void onResume() {
    super.onResume();
    if (BuildConfig.DEBUG) { // don't even consider it otherwise
        if (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_KEEP_SCREEN_ON);
        } else {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            Log.d("SCREEN", "Keeping screen on for debugging is now deactivated.");
        }
    }
}

To use it all you need to do is to attach a debugger, then leave the app (Home/Tasks button or turn the screen off) and then come back to it to trigger onResume.

要使用它,你所需要做的就是安装调试器,然后离开应用程序(Home/Tasks按钮或关闭屏幕),然后回到它来触发onResume。

Depending on what you usually debug, it may worth to put the above into onCreate so that it registers earlier and hopefully keeps the screen awake while debugging activity lifecycle before onResume.

根据您通常调试的内容,可能需要将上面的内容添加到onCreate中,这样就可以更早地注册,并希望在onResume之前调试活动生命周期时保持屏幕清醒。

In general I advise to use Run instead of Debug when trying out code and only attach the debugger when you found something: this will make your app tenfolds faster and this option the best there is.

一般来说,我建议在尝试代码时使用Run而不是Debug,并且只有在找到一些东西时才附加调试器:这将使您的应用程序的十倍速度更快,这个选项是最好的。

#2


21  

Try this in the adb shell, although it seems not to work on some devices:

在adb shell中尝试这一点,尽管它似乎不适合于某些设备:

svc power stayon usb

#3


15  

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.

我有Android版本2.3.6,在设置——>应用程序——>开发中,有一个选项可以在充电时保持清醒(也就是说,你的屏幕永远不会睡觉)。

#4


9  

Jorge Cevallos is right.

Jorge Cevallos是正确的。

For Android 4 and higher :

Android 4及以上版本:

  1. Go to Settings > About phone
  2. 转到设置>关于电话
  3. Touch several times (about 10 times) on "Build number".
  4. 在“构建号”上触摸几次(大约10次)。
  5. Then go back to Sttings menu and you'll find the "Developer options"
  6. 然后回到stums菜单你会找到"Developer options"
  7. Under "Developer Options", you will see "stay awake option ".
  8. 在“开发人员选项”下,您将看到“保持清醒选项”。

Have fun.

玩得开心。

#5


3  

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.

我为此创建了一个应用程序。您可以在谷歌上搜索它,播放“保持清醒以进行调试”,只有当启用了ADB调试时,它才能保持您的手机解锁/屏幕开启。它不仅局限于USB,还可以在wi-fi上使用。

#6


2  

I had the sampe problem. I found this app to keep the screen unlocked when the phone is connected.

我遇到了相同的问题。我发现这个应用程序可以在手机连接时保持屏幕解锁。

https://play.google.com/store/apps/details?id=com.gmail.developer.runks.enji

https://play.google.com/store/apps/details?id=com.gmail.developer.runks.enji

#7


2  

On console

在控制台

 while true; do adb shell input keyevent mouse ; sleep 1 ; done

#8


1  

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 );
    }
}

#9


0  

# find out if screen is on works on android 5.0+
screenOn=`adb shell dumpsys power | grep "Display Power" | grep ON`
if [ -z "$screenOn" ]; then
    echo "turning screen on"
    adb shell input keyevent KEYCODE_POWER
    # unlock by emulating slide up
    adb shell input touchscreen swipe 930 880 930 380
fi

#10


0  

Replace 12345 by your unlock code. Then this shell script unlocks your phone:

用解锁码替换12345。然后这个shell脚本解锁你的手机:

adb shell input keyevent KEYCODE_WAKEUP # activate 
adb shell input touchscreen swipe 530 1420 530 1120 # swipe up
adb shell input text 12345 # input password
adb shell input keyevent 66 # press enter

You should never disable security features on your phone (as pointed out above). Make sure nobody can read that script file either.

您不应该禁用手机上的安全功能(如上所述)。确保没有人能够读取那个脚本文件。

#11


-1  

You can just set the Screen Timeout to 30 minutes or turn it off. This option is under : Settings/Display/Screen Timeout

您可以将屏幕超时设置为30分钟或关闭它。此选项在以下:设置/显示/屏幕超时

Hope it helps.

希望它可以帮助。

#12


-1  

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.

    编写一个应用程序,它将强制屏幕超时设置为非常高。使用SCREEN_OFF_TIMEOUT或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.

    如果你的手机是根的,并且你和你正在开发的电脑连接在同一个网络上,你可以享受这个美妙的应用程序,它也有一个屏幕超时的选项:wifi adb。

#13


-1  

I have 2 devices with Android 2.3.3 and they are both having this option in Settings/Applications/Development and its called Stay Awake (Screen will never sleep while charging). And one of them is Samsung Galaxy S.

我有两款Android 2.3.3的设备,它们都在设置/应用程序/开发中有这个选项,它叫做“保持清醒”(充电时屏幕永远不会休眠)。其中之一就是三星Galaxy S。

Also I have a device with Android 2.2 (HTC Desire) an it has also the same functionality in the same location.

此外,我还有一款搭载Android 2.2 (HTC Desire)的设备,在相同的位置上也有相同的功能。

It is weird that your doesn't , do you use a custom ROM?

奇怪的是你没有使用自定义ROM?

#14


-2  

You can re-enable Developer options, which configurations are now hidden:

您可以重新启用开发人员选项,现在隐藏了哪些配置:

1 - Go to Settings > About > Software information > More...

1 - Go to Settings > About > Software information > More…

2 - Then touch Build number 7 times, which will give you a count down, and then say “you’re now a developer”.

2 -然后触摸构建7次,这会给你一个计数,然后说“你现在是一个开发人员”。

And Developer Options are back!

开发者选项又回来了!

#15


-4  

Use this in your Manifest:

在你的舱单中使用:

<uses-permission android:name="android.permission.WAKE_LOCK" />

and your screen won't turn off!

你的屏幕不会关闭!

#1


32  

There are multiple options, many of which have HORRIBLE (subjective) side effects. I'll list what I've found and what side effects I could think of.

有多种选择,其中许多有可怕的(主观的)副作用。我会列出我发现的以及我能想到的副作用。

I'm lazy, possibly like many others, and I don't like to keep on eye out for something unneccessarily. This means that the "Oh, I'll just turn this on while I'm working and then turn it off when finished" option is not a viable one. You will forget it and you will experience any of the sideeffects listed below eventually.

我很懒,可能和其他很多人一样,我不喜欢盯着不需要的东西。这意味着“哦,我在工作的时候打开它,然后在完成时关闭它”选项不是可行的。你会忘记它,最终你会体验到下面列出的任何副作用。

TL;DR

FLAG_KEEP_SCREEN_ON with a Debug.isDebuggerConnected() guard FTW! Stay awake when charging, Screen timeout and wake-lock are non-viable options if you just want to debug.
There's also an advantage of this solution working from API 1 AND wifi debugging!

使用Debug.isDebuggerConnected()保护FTW!如果您只是想调试的话,充电、屏幕超时和wake-lock都是不可行的选项。在API 1和wifi调试中也有这个解决方案的优势!

Settings > Developer Options > Stay awake when charging

Burn in: There should be a huge red flag anyone turning this on. It says "while charging" not "while debugging". Which means that even if your phone is plugged in to the mains it will keep on. This is especially bad if you have an AMOLED screen (e.g. Galaxy S series) which burns stuff in. I had this option on for a few weeks and now I have a permanent portrait status bar...

燃烧:应该有一个巨大的红旗谁打开这个。它说“充电时”而不是“调试时”。这意味着,即使你的手机接通电源,它也会继续。如果你有一个AMOLED屏幕(比如Galaxy S系列),它会把东西烧进去,那就更糟糕了。我有这个选择几个星期,现在我有一个永久肖像状态栏……

Notifications: Even if you use low brightness and don't forget to turn your screen off every time you put the phone down some apps wake your screen up if you get just a simple notification which leads to keeping it on most of the time while plugged in.

通知:即使你使用的是低亮度的屏幕,也不要忘记在你每次放下手机的时候关掉一些应用程序,如果你只收到一个简单的通知,那么你的屏幕就会被唤醒,这将导致你在大部分时间都处于开机状态。

Security: If you just leave your screen on while charging and you're needed quickly for something at work, the first thing won't be "Ah, let me lock my phone first" and you may expose your dirty secrets if you accidentally left it on. Let me note that if you're working in an environment where you can't trust your collegaues, I would reconsider that employment.

安全性:如果你在充电的时候只打开你的屏幕,而且你在工作中很快就需要一些东西,那么第一件事不会是“啊,让我先把手机锁上”,如果你不小心把手机开着,你可能会暴露你的脏秘密。我要指出的是,如果你在一个不能信任你的大学毕业生的环境中工作,我会重新考虑这份工作。

Settings > Display > Screen Timeout

This is very risky if you have lot of apps that give you notifications. Especially if you have some spammers (Facebook, Family Guy or even GMail if you get a lot of mails).

如果你有很多给你通知的应用,这是非常危险的。特别是如果你有一些垃圾邮件发送者(Facebook, Family Guy,甚至GMail,如果你收到很多邮件)。

Burn in: The risk is high with this as well. Now you don't even restrict it to "being on the wire" so it will just stay on whenever you forget to turn it off explicity or get a notification.

消耗:风险也很高。现在你甚至不把它限制在“在电线上”,所以只要你忘记关闭它,它就会继续运行,或者得到通知。

Battery drain: If you get one the screen will be on for the specified amount of time, draining your battery. And it will be on because sometimes you forget to turn it off, or just get a notification.

电池消耗:如果你得到一个屏幕将在指定的时间内打开,耗尽你的电池。它会打开,因为有时候你忘记关掉它,或者只是得到一个通知。

Hotpocket: if you get a notification while the phone is in your pocket the illumination from the screen and the confined space will heat your pockets and you may even get burned.

Hotpocket:如果你在口袋里的时候收到通知,屏幕上的照明和有限的空间会让你的口袋变热,你甚至会被烧伤。

Pocket dial: if your screen turns on while the phone is in your pocket the risk of a pocket dial with increase with every second. Nowadays this is less likely though, because the Phone app is usually well hidden, but my pocket likes to change the date very often or read my emails.

口袋拨号:如果你的屏幕在你的口袋里打开,口袋拨号的风险随着每一秒的增加而增加。现在,这种情况不太可能发生,因为手机应用程序通常都很隐蔽,但我的口袋喜欢经常更改日期或阅读我的电子邮件。

Security: imagine you're in a public place and your phone is on the table, your friends will most likely abuse your unlocked screen if you turn around for long enough to talk to someone or take a quick break. Especially if they're inebriated. Obviously shorter timeouts decrease this risk.

安全性:假设你在一个公共场所,你的手机放在桌子上,如果你长时间地转过头去和别人交谈或短暂休息,你的朋友很可能会滥用你的解锁屏幕。尤其是如果他们喝醉了。显然,更短的超时时间可以降低这种风险。

Using a wake-lock

Permission: You'll need to add a possibly unnecessary android.permission.WAKE_LOCK permission to your app (luckily should be easy to add for only debug variants thanks to Manifest Merger in the Gradle Plugin).

允许:您需要添加一个可能不必要的android.permission。WAKE_LOCK权限到您的应用程序(幸运的是,由于在Gradle插件中明显的合并,应该很容易添加调试变体)。

Coding: You'll also need to manage releasing the lock yourself and maybe need to create a Service just for this. I'd like to note here that I've yet to use this feature in Android.

编码:您还需要自己管理释放锁,可能需要为此创建一个服务。我想在这里指出,我还没有在Android中使用这个功能。

Useless: It also doesn't really help to keep the screen on, since it only keeps the CPU awake. See documentation.

无用:它也不能真正帮助保持屏幕打开,因为它只保持CPU清醒。见文档。

FLAG_KEEP_SCREEN_ON while a Debugger is attached

If you read the documentation for this one, you'll find a very close approximation to your problem.

如果您阅读了这篇文章的文档,您会发现与您的问题非常接近的地方。

Coding: to only downside I can think of here is that you need to modify some code, but it's extremely simple (assuming you have a BaseActivity that all your other activities extend):

编码:我认为唯一的缺点是您需要修改一些代码,但是它非常简单(假设您有一个所有其他活动都扩展的BaseActivity):

@Override protected void onResume() {
    super.onResume();
    if (BuildConfig.DEBUG) { // don't even consider it otherwise
        if (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_KEEP_SCREEN_ON);
        } else {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            Log.d("SCREEN", "Keeping screen on for debugging is now deactivated.");
        }
    }
}

To use it all you need to do is to attach a debugger, then leave the app (Home/Tasks button or turn the screen off) and then come back to it to trigger onResume.

要使用它,你所需要做的就是安装调试器,然后离开应用程序(Home/Tasks按钮或关闭屏幕),然后回到它来触发onResume。

Depending on what you usually debug, it may worth to put the above into onCreate so that it registers earlier and hopefully keeps the screen awake while debugging activity lifecycle before onResume.

根据您通常调试的内容,可能需要将上面的内容添加到onCreate中,这样就可以更早地注册,并希望在onResume之前调试活动生命周期时保持屏幕清醒。

In general I advise to use Run instead of Debug when trying out code and only attach the debugger when you found something: this will make your app tenfolds faster and this option the best there is.

一般来说,我建议在尝试代码时使用Run而不是Debug,并且只有在找到一些东西时才附加调试器:这将使您的应用程序的十倍速度更快,这个选项是最好的。

#2


21  

Try this in the adb shell, although it seems not to work on some devices:

在adb shell中尝试这一点,尽管它似乎不适合于某些设备:

svc power stayon usb

#3


15  

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.

我有Android版本2.3.6,在设置——>应用程序——>开发中,有一个选项可以在充电时保持清醒(也就是说,你的屏幕永远不会睡觉)。

#4


9  

Jorge Cevallos is right.

Jorge Cevallos是正确的。

For Android 4 and higher :

Android 4及以上版本:

  1. Go to Settings > About phone
  2. 转到设置>关于电话
  3. Touch several times (about 10 times) on "Build number".
  4. 在“构建号”上触摸几次(大约10次)。
  5. Then go back to Sttings menu and you'll find the "Developer options"
  6. 然后回到stums菜单你会找到"Developer options"
  7. Under "Developer Options", you will see "stay awake option ".
  8. 在“开发人员选项”下,您将看到“保持清醒选项”。

Have fun.

玩得开心。

#5


3  

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.

我为此创建了一个应用程序。您可以在谷歌上搜索它,播放“保持清醒以进行调试”,只有当启用了ADB调试时,它才能保持您的手机解锁/屏幕开启。它不仅局限于USB,还可以在wi-fi上使用。

#6


2  

I had the sampe problem. I found this app to keep the screen unlocked when the phone is connected.

我遇到了相同的问题。我发现这个应用程序可以在手机连接时保持屏幕解锁。

https://play.google.com/store/apps/details?id=com.gmail.developer.runks.enji

https://play.google.com/store/apps/details?id=com.gmail.developer.runks.enji

#7


2  

On console

在控制台

 while true; do adb shell input keyevent mouse ; sleep 1 ; done

#8


1  

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 );
    }
}

#9


0  

# find out if screen is on works on android 5.0+
screenOn=`adb shell dumpsys power | grep "Display Power" | grep ON`
if [ -z "$screenOn" ]; then
    echo "turning screen on"
    adb shell input keyevent KEYCODE_POWER
    # unlock by emulating slide up
    adb shell input touchscreen swipe 930 880 930 380
fi

#10


0  

Replace 12345 by your unlock code. Then this shell script unlocks your phone:

用解锁码替换12345。然后这个shell脚本解锁你的手机:

adb shell input keyevent KEYCODE_WAKEUP # activate 
adb shell input touchscreen swipe 530 1420 530 1120 # swipe up
adb shell input text 12345 # input password
adb shell input keyevent 66 # press enter

You should never disable security features on your phone (as pointed out above). Make sure nobody can read that script file either.

您不应该禁用手机上的安全功能(如上所述)。确保没有人能够读取那个脚本文件。

#11


-1  

You can just set the Screen Timeout to 30 minutes or turn it off. This option is under : Settings/Display/Screen Timeout

您可以将屏幕超时设置为30分钟或关闭它。此选项在以下:设置/显示/屏幕超时

Hope it helps.

希望它可以帮助。

#12


-1  

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.

    编写一个应用程序,它将强制屏幕超时设置为非常高。使用SCREEN_OFF_TIMEOUT或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.

    如果你的手机是根的,并且你和你正在开发的电脑连接在同一个网络上,你可以享受这个美妙的应用程序,它也有一个屏幕超时的选项:wifi adb。

#13


-1  

I have 2 devices with Android 2.3.3 and they are both having this option in Settings/Applications/Development and its called Stay Awake (Screen will never sleep while charging). And one of them is Samsung Galaxy S.

我有两款Android 2.3.3的设备,它们都在设置/应用程序/开发中有这个选项,它叫做“保持清醒”(充电时屏幕永远不会休眠)。其中之一就是三星Galaxy S。

Also I have a device with Android 2.2 (HTC Desire) an it has also the same functionality in the same location.

此外,我还有一款搭载Android 2.2 (HTC Desire)的设备,在相同的位置上也有相同的功能。

It is weird that your doesn't , do you use a custom ROM?

奇怪的是你没有使用自定义ROM?

#14


-2  

You can re-enable Developer options, which configurations are now hidden:

您可以重新启用开发人员选项,现在隐藏了哪些配置:

1 - Go to Settings > About > Software information > More...

1 - Go to Settings > About > Software information > More…

2 - Then touch Build number 7 times, which will give you a count down, and then say “you’re now a developer”.

2 -然后触摸构建7次,这会给你一个计数,然后说“你现在是一个开发人员”。

And Developer Options are back!

开发者选项又回来了!

#15


-4  

Use this in your Manifest:

在你的舱单中使用:

<uses-permission android:name="android.permission.WAKE_LOCK" />

and your screen won't turn off!

你的屏幕不会关闭!