使用方向调整 Android phone 屏幕亮度

Adjust Andriod phone screen brightness using orientation

如何使用phone方向调整屏幕亮度?例如,纵向时亮度最大,横向时亮度最小。

在您的 activity class 中使用以下方法:(检查方向和控制亮度)

 @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    Settings.System.putInt(context.getContentResolver(),
               Settings.System.SCREEN_BRIGHTNESS, 0);
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
                   Settings.System.putInt(context.getContentResolver(),
               Settings.System.SCREEN_BRIGHTNESS, 100);
        }
    }

权限:

<uses-permission
      android:name="android.permission.WRITE_SETTINGS"
      tools:ignore="ProtectedPermissions" />