关闭屏幕在Android [英] Turn off screen on Android

查看:227
本文介绍了关闭屏幕在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开和关闭显示器发生某个操作后(让我们只是担心转动屏幕关闭现在)。从我从唤醒锁明白了,这就是我:

I am trying to turn on and off the display after a certain action happens (Lets just worry about turning the screen off for now). From what I understand from wake lock, this is what I have:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);    
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");

当我读了计算器其他职位和其他地方,他们似乎告诉我,PARTIAL_WAKE_LOCK将关闭屏幕。但是,如果我读的SDK,它说,它只会让屏幕关闭。因此,我认为这是不对的。

When I read other posts on stackoverflow and else where, they seem to tell me that PARTIAL_WAKE_LOCK will turn the screen off. But if I read the SDK it says that it will only allow the screen to be turned off. So I think this isn't right.

任何提示将是有益的! 谢谢你,

Any hints would be helpful! Thanks,

迈克

推荐答案

有两种选择转动屏幕关闭:

There are two choices for turning the screen off:

PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);

// Choice 1
manager.goToSleep(int amountOfTime);

// Choice 2
PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Your Tag");
wl.acquire();
wl.release();

您可能会需要这个权限也:

You will probably need this permission too:

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

更新:

试试这个方法;机器人自动关闭屏幕,一旦光照水平足够低。

Try this method; android turns off the screen once the light level is low enough.

WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
getWindow().setAttributes(params);

这篇关于关闭屏幕在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆