Android基础教程——调节系统屏幕亮度

import android.app.Activity;

import android.content.ContentResolver;

import android.provider.Settings;

import android.provider.Settings.SettingNotFoundException;

import android.view.WindowManager;



public class ScreenBrightness {



	public static int getScreenBrightness(Activity activity) {

		int value = 0;

		ContentResolver cr = activity.getContentResolver();

		try {

			value = Settings.System.getInt(cr,

					Settings.System.SCREEN_BRIGHTNESS);

		} catch (SettingNotFoundException e) {



		}

		return value;

	}



	public static void setScreenBrightness(Activity activity, int value) {

		WindowManager.LayoutParams params = activity.getWindow()

				.getAttributes();

		params.screenBrightness = value / 255f;

		activity.getWindow().setAttributes(params);

	}

}




此类直接调用系统功能来调节屏幕参数!
注意如果调用

setScreenBrightness()

方法时传入的value值为0,那屏幕就全暗了,然后你的设备就一直暗着,直到重新启动系统了,所以在调用前最好先对传值进行下处理

你可能感兴趣的:(android)