隐藏调用API中的机器人把屏幕关闭人把、屏幕、机器、API

2023-09-11 20:22:04 作者:禽兽丶放开那母猪

我在考虑使用隐藏的API可以将屏幕关闭我的应用程序。 setScreenState从http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/os/Power.java我想要做什么,但其隐藏的API。这是否意味着我不应该使用它?我认为它是一个相当稳定的API。 目前,我设置屏幕超时为1毫秒,然后再重新设置超时时间,一旦屏幕关闭。然而,Android的忽略了1毫秒,而是它需要大约3秒关闭,有时它完全忽略它并不会关闭。 有什么建议?

I'm thinking about using a hidden api to turn the screen off in my app. setScreenState from http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/os/Power.java does what I want, but its a hidden API. Does that mean I shouldn't use it? I would think its a fairly stable api. Currently, I'm setting the screen timeout to 1 millisecond, and then resetting the timeout once the screen turns off. However, android ignores the 1 millisecond and instead it takes about 3 seconds to turn off and sometimes it ignores it completely and doesn't turn off. Any suggestions?

推荐答案

下面是我所做的工作,各地要使屏幕的睡眠。您可以在活动窗口中做到这一点。我配对它降低了睡眠超时5秒,这个自定义锁屏活动。你可以在我的项目页面上查看我所有的源代码,但这里的有关打开屏幕关闭该为我工作在一个机器人的相关部分。

Here's what I did to work around the need to make the screen sleep. You can do this in an activity window. I paired it with reducing the sleep timeout to 5 sec for this custom lockscreen activity. You can view all my source over at my project page, but here's the relevant part about turning the screen off that worked for me on a droid.

public void setBright(float value) {
    Window mywindow = getWindow();
    WindowManager.LayoutParams lp = mywindow.getAttributes();
    lp.screenBrightness = value;
    mywindow.setAttributes(lp);
}

//call this task to turn off the screen in a fadeout.


class Task implements Runnable {
    public void run() {                
        if (bright != 0) {
            setBright(bright/100); //start at 10% bright and go to 0 (screen off)
            bright--;
            serviceHandler.postDelayed(myTask, 100L);
        } else {
            setBright((float) 0.0); 
            bright = 10;//put bright back
        }
    }
}

我用的处理任务作为测试的方法,它工作时,我从onBack pressed在第一个版本的说法。现在,我只是有活动setBright为0.0的的onCreate。这使得它如此画面实际上并没有打开,即使我的用户通过一个偶然的音量键preSS唤醒CPU。当我想在屏幕去,我有钥匙事件调用setBright的值大于0(1.0表示最大亮)。我很幸运,这适用于我的自定义锁屏的活动。我发现,改变文字的亮度系统设置不能像这样工作,并且不会让屏幕关闭。

I used the handler task as a test for the method, it worked when I called it from onBackPressed in the first build. Now, I just have the activity setBright to 0.0 at onCreate. This makes it so the screen doesn't actually turn on even if my user wakes the CPU by an accidental volume key press. When I want the screen to go on, I have the key event call setBright to a value greater than 0 (1.0 means max bright). I'm very lucky this works for my custom lockscreen activity. I found that changing the literal brightness system setting doesn't work like this, and won't get the screen off.

检查出了对我的项目的svn HTTP我其它来源:// code.google.com / P / mylockforandroid /来源/结帐

check out my other source over on my project svn http://code.google.com/p/mylockforandroid/source/checkout

有多难,你认为这是要求Android团队为转动屏幕关闭或定义屏幕是否应该通过锁定介质更换醒来添加支持类似于如何,你可以编写一个替代首页启动的应用程序?

How hard do you think it is to ask the android team to add support for turning the screen off or defining whether the screen should wake via Lock mediator replacement similarly to how you could program an alternative Home Launcher app?

 
精彩推荐
图片推荐