android on off控件,Turn off/on android screen
问题
I am trying to turn the android screen off and then on again, after a few seconds. The "turn off" part works, with this code:
WindowManager.LayoutParams layoutParam = getWindow().getAttributes();
oldBrightness = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS)/255f;
layoutParam.screenBrightness = 0;
layoutParam.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(layoutParam);
But then, when I try to turn the screen on again, it does not work with this code:
WindowManager.LayoutParams layoutParam = getWindow().getAttributes();
layoutParam.screenBrightness = oldBrightness;
layoutParam.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(layoutParam);
Any idea to solve that ?
thanks
回答1:
I think U can try Powermanager WakeLock maybe it will work. I m using this code in my application. and it works well. :)
Also u need to set permission in manifest.
// Manifest Permission
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();
回答2:
First off, are you sure about the "/255f" in this line:
oldBrightness = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS)/255f;
What is the value in "oldBrightness" when you get/set it ?
Maybe you could try this:
PowerManager.WakeLock lck = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
lck.acquire();
The normal wake lock doesn't turn the screen on but causes it to stay on when a user causes it. But this flag forces the screen to turn on immediately. It requires the "android.permission.WAKE_LOCK".
More about it:
http://developer.android.com/reference/android/os/PowerManager.html#PARTIAL_WAKE_LOCK
And the screen properties (on, off, bright, dim, etc.):
http://developer.android.com/reference/android/os/PowerManager.html
来源:https://stackoverflow.com/questions/10469511/turn-off-on-android-screen
android on off控件,Turn off/on android screen相关推荐
- android判断一个控件是否获得光标,Android View获取焦点
做项目的时候遇到一个bug,在一个Activity中打开DrawerLayout,这样就会遇到一个问题,在Activity中的EditText的焦点还在,这样根据项目中的代码逻辑数据就会同步不过来,这 ...
- android java 给控件设置style,在Android Lollipop for Material Design中为SwitchCompat按钮设置样式/着色...
我一直在尝试查找资源,解释如何在Material Design主题中设置切换按钮的样式 . 现在使用新的appcompat-v7:21,着色小部件非常简单 . 只要您使用appcompat-v7:21 ...
- android动态添加控件在指定位置,Android 如何动态添加 View 并显示在指定位置。
引子 最近,在做产品的需求的时候,遇到 PM 要求在某个按钮上添加一个新手引导动画,引导用户去点击.作为 RD,我哗啦啦的就写好相关逻辑了.自测完成后,提测,PM Review 效果. 看完后,PM ...
- android添加图片控件代码,如何在android studio中添加图标图像按钮
我想设计这种类型的应用程序的布局(如图所示).在此布局中,当我们单击圆形图标时,它将移至下一页.我想知道它是如何完成的. 解决方法: 在抽屉文件夹中创建circle_background.xml并将此 ...
- Android 自定义组合控件小结
Android 自定义组合控件小结 引言 接触Android UI开发的这段时间以来,对自定义组合控件有了一定的了解,为此小结一下,本文小结内容主要讨论的是如何使用Android SDK提供的布局和控 ...
- Android活动,控件,碎片,广播,数据库小总结
系统架构与开发环境搭建 3月2日Android Activities代码练习 3月5日 Intent的应用与传值 3月9日 1:显式Intent与隐式Intent的区别 显式Inten ...
- Android使用ListView控件问题
Android使用ListView控件问题: The application has stopped unexpectedly, please try again. 开发环境:android 1.6 ...
- Android的WebView控件载入网页显示速度慢的究极解决方案
Android的WebView控件载入网页显示速度慢的究极解决方案 [转载来源自http://hi.baidu.com/goldchocobo/] Android客户端中混搭HTML页面,会出现虽然H ...
- android 动态设置padding,Android动态设置控件大小以及设定margin以及padding值
http://www.aichengxu.com/Java/73893.htm Android动态设置控件大小以及设定margin以及padding值,有需要的朋友可以参考下. 一.概述 在andro ...
最新文章
- 冷却水的循环方式有哪几种_一种清洁环保高效的方法处理工业循环冷却水
- boost::math::quadrature::exp_sinh用法的测试程序
- android java 延时函数,如何在Android中设置文本之间的延迟
- C语言 字符串大小写转换
- Android 窗口Dialog 代码以及使用
- UI素材干货|听说UI设计师更喜欢Sketch
- C语言第七讲,函数入门.
- 【转】Odoo开发之:工作流 workflow
- 隐马尔可夫模型简单理解
- 修改mysql的authen_MySQL数据库出现Authentication plugin怎么办
- Postgresql - cursor介绍
- 360校招 求立方体表面积
- 车载网络测试 - 车载以太网 - 网络配置方法
- solr中文同义词检索的配置讲解
- 澳洲留学:说说在澳洲打工的那些苦与痛
- 第二章,人脸识别与管理系统界面开发(WinForm界面增强,OpenCV-Python智能识别)
- 王权理财:鹰派寒气逼人金价开启跌势,天然气跌势暂缓有望反弹拉升
- Java后端笔记 _Static关键字
- Open Inventor 简介
- C# FTP上传(支持断点续传)
热门文章
- 关于electron + vue3 打包所遇见问题
- 无法显示所有文件和文件夹的终极解决方法
- DolpinScheduler2.0.5详细介绍与踩坑实战
- 施耐德PLC UNITY PRO XL 通过NOC模块与第三方硬件通讯
- 最有效的注意力集中训练法
- Android通过Mapping文件retrace混淆后的堆栈
- [iOS开发]文档导读
- ListView和RecyclerView(通用)里面的时间倒计时
- raid磁盘阵列常见故障类型和解决方案
- Bentley.HAMMER.XM.v08.09.400.34.zip