设置新亮度后,我的屏幕没有刷新。我用Google搜索,尝试了几件事,我做错了什么?
public class Brightness extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.brightness);
setResult(RESULT_OK);
Button low = (Button)findViewById(R.id.low);
low.setOnClickListener( new Button.OnClickListener()
{
public void onClick(View arg0)
{
setUp(100);
}});
Button medium = (Button)findViewById(R.id.medium);
medium.setOnClickListener( new Button.OnClickListener()
{
public void onClick(View arg0)
{
setUp(200);
}});
Button high = (Button)findViewById(R.id.high);
high.setOnClickListener( new Button.OnClickListener()
{
public void onClick(View arg0)
{
setUp(255);
}});
}
public void setUp(int SysBackLightValue)
{
android.provider.Settings.System.putInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, SysBackLightValue);
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = SysBackLightValue;
getWindow().setAttributes(layoutParams);
finish();
}
}
这是它调用Brightness.java
的活动if (resultCode == Activity.RESULT_OK && requestCode == 10)
{
Log.i("login", "In ActivityRedult My screen brightness is ");
try
{
oldBrightness = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = oldBrightness;
getWindow().setAttributes(layoutParams);
}
catch (SettingNotFoundException e1)
{
Log.i("login", "CATCH My screen brightness is " + e1.toString());
e1.printStackTrace();
}
}
}
答案 0 :(得分:0)
我不记得这样做的原因,但有两种设置亮度的方法,它们在不同的时间使用(或者可能由不同的api支持)
以下是我在市场上为我的应用程序Super Dimmer使用的代码的一部分(根据您的情况进行了重构)。请尝试使用此代码:
oldBrightness = Settings.System.getInt(this.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
Settings.System.putInt(this.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, oldBrightness);
WindowManager.LayoutParams llayoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = (float) (oldBrightness/ 255.0);
getWindow().setAttributes(layoutParams);
我认为不同之处在于你错过了putInt()。此外,您的屏幕是否始终全亮?我可能是错的,但在我的应用程序中,当我设置layoutParams属性时,我将除以255,它就像魅力一样。