简体   繁体   English

如何以编程方式禁用“省电”模式。 (Android)

[英]How to disable “Power saving” mode programmatically. (Android)

Currently I'm trying to develop a 2D game for Android devices by using OpenGL ES , but Android OS makes it as painful as possible. 目前,我正在尝试使用OpenGL ES开发适用于Android设备的2D游戏 ,但Android OS使其尽可能地痛苦。

It look very nice and smoothly running at 60FPS by consuming all the battery it can. 它看起来很不错,并且通过消耗所有可能的电池以60FPS的速度平稳运行 Then suddenly I've realized that. 然后突然我意识到了这一点。 Enabling " Power save " mode ( Galaxy S III , etc), couses FPS drop to 40 . 启用“ 省电 ”模式( Galaxy S III等), 导致FPS降至40

So I've decided to increase game speed and limit timer to 40FPS , so it will be possible to play at 40FPS smoothly. 因此,我决定提高游戏速度并将计时器限制为40FPS ,以便可以流畅地以40FPS进行游戏。

And here comes another problem. 这又带来了另一个问题。 This times objects that moves are flickering randomly even if the max is FPS set to 30 and calculation/drawings are on the same thread. 即使最大FPS设置为30,并且计算/绘图在同一线程上,这一次移动的对象也会随机闪烁 when " Power save " is disabled(Disabled from devices menu) it keep running smoothly. 禁用“ 节能 ”(从设备菜单中禁用)后,它将保持平稳运行。

In short " Power save " mode is slowing down app by slowing down OpenGL ES functions randomly even if it is not nessecery to drop FPS to 40 . 简而言之,“ 省电 ”模式通过随机降低OpenGL ES功能来减慢应用程序运行速度,即使不必将FPS降至40 (sometimes a function that takes 2-3ms to execute, takes 13-14ms and the others are running normaly) (有时一个函数需要2-3ms的时间执行,需要13-14ms的时间,其他函数正常运行)

I wonder if there is a way to disable "Power save" mode in code and enable it back on exit. 我想知道是否有一种方法可以在代码中禁用“省电”模式并在退出时将其启用。

PS: To keep screen on I'm using next lines: PS:要保持屏幕显示状态,请使用下一行:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "DoNotDimScreen");
    this.mWakeLock.acquire();

也许这可以帮助您:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM