android,在设置亮度的时候,为什么没有立即生效?要关闭屏幕或自动变暗后,才生效。改变自动调节或手动调节模式时,倒是一小会儿后生效了。请问,如何解决?
publicvoid setBrightness(int brightness)
{
// if (sysAutomaticMode)// return;
Settings.System.putInt(context.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, brightness);
}
android原码使用了:
IPowerManager power = IPowerManager.Stub.asInterface(
ServiceManager.getService("power"));
if (power != null) {
power.setBacklightBrightness(brightness);
}
但是自己写的用不了IPowerManager啊。
还有,调节亮度是在服务里操作的。
android,在设置亮度的时候,为什么没有立即生效?
答案:2 悬赏:50
解决时间 2021-04-28 04:14
- 提问者网友:年齡太小℡蘿莉
- 2021-04-27 12:30
最佳答案
- 二级知识专家网友:滚出爷的世界
- 2021-04-27 13:04
你的代码不够完整。应该设置如下:
public void setBrightness(float fl) {
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
int brightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS,0);
// lp.screenBrightness = brightness/255.0f;
lp.screenBrightness = fl;
this.getWindow().setAttributes(lp);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness);
}
public void setBrightness(float fl) {
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
int brightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS,0);
// lp.screenBrightness = brightness/255.0f;
lp.screenBrightness = fl;
this.getWindow().setAttributes(lp);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness);
}
全部回答
- 1楼网友:一池湖水
- 2021-04-27 14:04
private int getscreenmode(){
int screenmode=0;
try{
screenmode = settings.system.getint(getcontentresolver(), settings.system.screen_brightness_mode);
}
catch (exception localexception){
}
return screenmode;
}
private int getscreenbrightness(){
int screenbrightness=255;
try{
screenbrightness = settings.system.getint(getcontentresolver(), settings.system.screen_brightness);
}
catch (exception localexception){
}
return screenbrightness;
}
private void setscreenmode(int paramint){
try{
settings.system.putint(getcontentresolver(), settings.system.screen_brightness_mode, paramint);
}catch (exception localexception){
localexception.printstacktrace();
}
}
private void savescreenbrightness(int paramint){
try{
settings.system.putint(getcontentresolver(), settings.system.screen_brightness, paramint);
}
catch (exception localexception){
localexception.printstacktrace();
}
}
private void setscreenbrightness(int paramint){
window localwindow = getwindow();
windowmanager.layoutparams locallayoutparams = localwindow.getattributes();
float f = paramint / 255.0f;
locallayoutparams.screenbrightness = f;
localwindow.setattributes(locallayoutparams);
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息