提问者:小点点

使用方向调整Andriod手机屏幕亮度


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


共1个答案

匿名用户

在你的activity课上,使用下面的方法:(检查方向和控制亮度)

 @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" />