Java tutorial
//package com.java2s; //License from project: Apache License import android.app.Activity; import android.os.Looper; import android.view.WindowManager; public class Main { public static float getBrightness(Activity activity) { return activity.getWindow().getAttributes().screenBrightness; } public static boolean getBrightness(final Activity activity, float brightness) { final WindowManager.LayoutParams layoutParams = activity.getWindow().getAttributes(); layoutParams.screenBrightness = brightness; if (isUIThread()) activity.getWindow().setAttributes(layoutParams); else activity.runOnUiThread(new Runnable() { @Override public void run() { activity.getWindow().setAttributes(layoutParams); } }); return false; } public static boolean isUIThread() { return Looper.getMainLooper().getThread().getId() == Thread.currentThread().getId(); } }