我正在开发打开屏幕的应用程序(如果它已被禁用)并将屏幕亮度更改为255.一切正常。设备的亮度变得最大。但是在稍微延迟之后,例如5秒,亮度必须返回到先前的值。但是这个值只有在阻止设备不能立即影响时才会影响,因为设置了最大值。我怎样才能立即影响价值。
P.S。抱歉我的英文。
更新
protected void onHandleIntent(Intent intent) {
float brightnessFloat = 1.0f;
getOldBrightness();
setUpNewBrightness(brightnessFloat);
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
System.out.println(e.toString());
}
returnOldBrightness();
}
private void getOldBrightness() {
try {
oldBrightness = Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);
} catch (Settings.SettingNotFoundException e) {
Log.e(LOG_TAG, e.toString());
}
}
private void setUpNewBrightness(float brightness) {
int brightnessInt = (int) brightness * 255;
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightnessInt);
Log.i(LOG_TAG, "Old brightness: " + oldBrightness + " ===== New brightness: " + brightnessInt);
startInvisibleActivity(brightness, false);
}
private void returnOldBrightness() {
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, oldBrightness);
float brightness = (float) oldBrightness / 255;
Log.i(LOG_TAG, "New brightness: " + brightness);
startInvisibleActivity(brightness, true);
}
private void startInvisibleActivity(float brightness, boolean screenUnlocked) {
Intent invisibleActivityIntent = new Intent(getBaseContext(), InvisibleActivity.class);
invisibleActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
invisibleActivityIntent.putExtra(BRIGHTNESS_VALUE, brightness);
invisibleActivityIntent.putExtra(SCREEN_UNLOCKED, screenUnlocked);
startActivity(invisibleActivityIntent);
}