Android 系统设置的权限(背光设置)
2010-03-25 21:21:00 来源:WEB开发网在ANDROID中,系统设置的权限一大堆,让我一直很头痛,今天我以背光调节为例子,来讲解一下相关权限,要调节背光设置,先把设置前光的JAVA源码写上:
初始化:
public void InitBrightness()
{
//相关控件,用SEEKBAR来调节背光
mChangeBtName = (TextView)this.findViewById(R.id.play_bt_change_name);
mChangeBar = (SeekBar)this.findViewById(R.id.bt_set_seekbar);
//mChangeBar.setOnFocusChangeListener(this);
//获取当前背光亮度并在SEEKBAR上呈现
try {
mOldBrightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
} catch (SettingNotFoundException snfe) {
mOldBrightness = MAXIMUM_BACKLIGHT;
}
Log.v("Brightness", "number" + mOldBrightness);
mChangeBar.setMax(MAXIMUM_BACKLIGHT - MINIMUM_BACKLIGHT);
Log.v("Brightness max", "setmax:" + (MAXIMUM_BACKLIGHT - MINIMUM_BACKLIGHT));
mChangeBar.setProgress(mOldBrightness - MINIMUM_BACKLIGHT);
mChangeBtName.setText(String.valueOf((mOldBrightness - MINIMUM_BACKLIGHT)/25));
//进度条控制
mChangeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStartTrackingTouch(SeekBar bar) {
}
public void onProgressChanged(SeekBar bar, int progress,boolean fromtouch) {
Log.v("Progress", "num:" + progress);
int step = 25;
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, progress + MINIMUM_BACKLIGHT);
Log.v("Progress", "putINTOK");
setBrightness(progress + MINIMUM_BACKLIGHT);
mChangeBtName.setText(String.valueOf(progress/step));
}
public void onStopTrackingTouch(SeekBar bar) {
}
});
}
设置背光函数:
private void setBrightness(int brightness) {
更多精彩
赞助商链接