单击进度时,程序会显示错误关闭。 Settings.System.putInt(cResolver,Settings.System.SCREEN_BRIGHTNESS,亮度); >
出现以下错误
未被授予此权限:android.permission.WRITE_SETTINGS。 android.os.Parcel.readException上的MainActivity $ 1.onStopTrackingTouch(MainActivity.java:129)android.widget.SeekBar.onStopTrackingTouch
brightbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
**Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, brightness);**
WindowManager.LayoutParams layoutpars = window.getAttributes();
layoutpars.screenBrightness = brightness / (float)255;
window.setAttributes(layoutpars);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(progress<=20)
{
brightness=20;
}
else
{
brightness = progress;
}
Toast.makeText(getApplication(),"brightness:"+brightness,Toast.LENGTH_LONG).show();
float perc = (brightness /(float)255)*100;
txtPerc.setText((int)perc +" %");
}
});