您的位置:首页 > 移动开发 > Android开发

快速唤醒USB调试连接中的android机

2015-03-13 16:16 686 查看
如果调试过程中有一段时间没有操作android机,那么它会自动关闭屏幕。这时需要按一下电源按钮才能唤醒。

怎样才能去掉这个烦人的按下电源按钮的操作呢?

经过搜索与尝试,发现了下面的方案:

“利用adb shell am start命令启动一个能点亮屏幕的app。”

1. 构造app

这个能强制点亮屏幕的app使用了PowerManager的 ACQUIRE_CAUSES_WAKEUP标记。

api reference对该标记的说明:“Normal wake locks don't actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to
turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately.”

关键代码如下:

powerManager = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
@SuppressWarnings("deprecation")
int levelAndFlags = PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK;
wakeLock = powerManager.newWakeLock(levelAndFlags, "com.hoxily.wakeup");
wakeLock.acquire(5000);


点亮屏幕后app即可退出了。

2. 添加外部工具按钮

在Eclipse IDE的外部工具按钮上进行配置,执行adb命令:

adb shell am start -n com.hoxily.wakeup/.MainActivity

如图所示



参考文档

把外部工具和构建器集成到 Eclipse 中,http://www.ibm.com/developerworks/cn/education/opensource/os-eclipse-tools/index.html

http://developer.android.com

附件

Wakeup.apk, http://pan.baidu.com/s/1ntE9PlJ
Wakeup-src.zip,http://pan.baidu.com/s/1dD2ETo9
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: