android 设置屏幕亮度

设置屏幕亮度,不多说,代码如下:


	protected void setBrightness() {
		
		WindowManager.LayoutParams lp = ((Activity) mContext).getWindow().getAttributes();
		int brightness =  Settings.System.getInt(mContext.getContentResolver(), 
					Settings.System.SCREEN_BRIGHTNESS,0);
//		if(brightness <217)
//			lp.screenBrightness = 0.85f;
//		else
//		brightness += 10;
//		if(brightness > 255)
//			brightness = 60;
		
		lp.screenBrightness = brightness/255.0f;
		((Activity) mContext).getWindow().setAttributes(lp);
		
		Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness);
	}

同时需要加入权限

 

你可能感兴趣的:(android相关)