I have solved this problem today.
由于你首先必须把许可输入贵国的Manifest.xml档案:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
档案中的确切位置如何?
<manifest>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<application>
<activity />
</application>
</manifest>
这项许可规定,允许你改变影响其他应用的环境。
现在,你可以自动地把光明放开。
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); //this will set the automatic mode on
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); //this will set the manual mode (set the automatic mode off)
自动模式现在是否变成或消失? 你们可以获取信息
int mode = -1;
try {
mode = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE); //this will return integer (0 or 1)
} catch (Exception e) {}
因此,如果你想要手工改变光明,你就应该首先确定人工模式,然后才能改变光明。
注:SCREEN_BRLINESS_MODE_AUTOMATIC 1
注
您应利用这一方法。
if (mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
//Automatic mode
} else {
//Manual mode
}
而不是
if (mode == 1) {
//Automatic mode
} else {
//Manual mode
}
现在,你可以人工改变亮度
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness); //brightness is an integer variable (0-255), but dont use 0
内容提要
try {
int brightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); //returns integer value 0-255
} catch (Exception e) {}
Now everything is set properly, but... you can t see the change yet.
You need one more thing to see the change!
Refresh the screen... so do this:
try {
int br = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); //this will get the information you have just set...
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = (float) br / 255; //...and put it here
getWindow().setAttributes(lp);
} catch (Exception e) {}
页: 1
<uses-permission android:name="android.permission.WRITE_SETTINGS" />