天天看点

android-code-调节屏幕亮度

/**
   * 设置当前屏幕亮度值 0--255
   */
  private void saveScreenBrightness(int paramInt) {
    try {
      Settings.System.putInt(getContentResolver(),
          Settings.System.SCREEN_BRIGHTNESS, paramInt);
    } catch (Exception localException) {
      localException.printStackTrace();
    }
  }

  /**
   * 保存当前的屏幕亮度值,并使之生效
   */
  private void setScreenBrightness(int paramInt) {
    Window localWindow = getWindow();
    WindowManager.LayoutParams localLayoutParams = localWindow
        .getAttributes();
    float f = paramInt / 255.0F;
    localLayoutParams.screenBrightness = f;
    localWindow.setAttributes(localLayoutParams);
  }      
if (value >= 1 && value <= 13) {

      Intent intent = new Intent(
          ContantUtils.BROADCAST_SETTING_BRIGHTNESS);
      intent.putExtra("data", (value - 1) * 20);
      application.sendBroadcast(intent);
    }      

继续阅读