0

I'm working on a camera app and I'd like to be able to brighten the screen when capturing a selfie- this way it acts as a flash. Instagram is able to do this without requesting the ACTION_MANAGE_WRITE_SETTINGS permission. Any ideas on how I can replicate this functionality without having to kick the user to the settings.

All help is greatly appreciate. Thank you.

Dick Lucas
  • 12,289
  • 14
  • 49
  • 76

1 Answers1

1

An application has access to its own screen brightness without a permission request. This code should work while your app has focus. You will see your brightness reset back to system when you switch applications.

import android.view.WindowManager;


public static void updateScreenBrightness(Activity activityContext) {
    WindowManager.LayoutParams windowParams = activityContext.getWindow().getAttributes();
    windowParams.screenBrightness = 100f / 100f; // Valid brightness values are 0.0 - 1.0
    activityContext.getWindow().setAttributes(windowParams);
}
John Lord
  • 1,941
  • 12
  • 27