下面这段代码只是起到抛砖引玉的作用,你能做的还很多。
private void setBrightness(int brightness) {
try {
Method getServiceMethod = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
IBinder binder = (IBinder) getServiceMethod.invoke(null, new Object[] { "power" });
Method asInterfaceMehod = Class.forName("android.os.IPowerManager$Stub").getMethod("asInterface", new Class[] {IBinder.class});
Object powerMan = asInterfaceMehod.invoke(null, binder);
Method setBacklightBrightness = powerMan.getClass().getMethod("setBacklightBrightness", new Class[]{int.class});
setBacklightBrightness.invoke(powerMan, new Object[]{brightness});
} catch (Exception doe) {
Log.i(TAG, "setBrightness error");
}
}