方法一
private void setPowerWakeLock() {
File file = new File("/sys/power/wake_lock");
if (file.exists()) {
try {
FileOutputStream fos = new FileOutputStream(file);
PrintWriter pw = new PrintWriter(fos);
pw.write("PowerManagerService.noSuspend");
pw.flush();
fos.flush();
fos.close();
pw.close();
} catch (Exception e) {
}
}
}
方法二
private void setWakeLock() {
try {
Process process = null;
process = Runtime.getRuntime().exec("su");
OutputStream out = process.getOutputStream();
out.write(("echo PowerManagerService.noSuspend > /sys/power/wake_lock").getBytes());
Thread.sleep(100);
out.flush();
out.close();
Log.w(TAG, "setPowerWakeLock: 写入成功");
} catch (IOException | InterruptedException e) {
Log.w(TAG, "setPowerWakeLock: 写入失败");
e.printStackTrace();
}
}
不过以上方法都需要设备Root,或者拥有Root权限

本文介绍了两种方法来阻止Android系统进入深度休眠状态,但这些方法都要求设备已Root或具备Root权限。详细内容包括具体实现步骤。
8028

被折叠的 条评论
为什么被折叠?



