0

I am getting 255 brightness when auto brightness is on in my phone (HTC Desire HD (2.3.3)).

My code

int value = Settings.System.getInt(c.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS);

How can I get brightness level when auto brightness is on?

Tried

I tried, before getting brightness, I am setting manual mode. but getting 0 brightness when I set mode to manual.

Settings.System.putInt(getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS,
                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);

How can I get brightness level when I phone is having auto brightness is on?

halfer
  • 19,824
  • 17
  • 99
  • 186
Bhavesh Hirpara
  • 22,255
  • 15
  • 63
  • 104

2 Answers2

1

you need to pass different key in case of auto-brightness

float brightness = android.provider.Settings.System.getInt(getContentResolver(),
                    "screen_auto_brightness_adj");

it should return value from -1 to +1

user3207655
  • 188
  • 2
  • 15
  • there is no such setting in android 5 (lollipop), so it throws an exception. It is as well not listed as a constant in `Settings.System`. Are you sure it works(worked)? – Antek Jun 28 '17 at 09:39
0
WindowManager.LayoutParams oLayOutParam = use from an activity getWindow().getAttributes();

oLayOutParam.screenBrightness is the value of brightness.

Ivan Ferić
  • 4,725
  • 11
  • 37
  • 47
android2013
  • 415
  • 2
  • 5
  • I can do this when my activity is running. actually I implemented service for which you can change brightness from anywhere by shaking. I can not get window from service. `WindowManager.LayoutParams oLayOutParam = getWindow().getAttributes();` will return in float. that is limited for activity itself.once activity is finished, it will be roll-backed. – Bhavesh Hirpara Jan 25 '13 at 08:46
  • You can always start an activity from service and then finish it as soon as you read brightness , you can set the brightness also using above API. – android2013 Jan 25 '13 at 09:31
  • similar thread http://stackoverflow.com/questions/5032588/cant-apply-system-screen-brightness-programmatically-in-android you need to have transparent activity. – android2013 Jan 25 '13 at 09:31
  • I already tried with this.. see my implemetation but does not change brightness when fakeactivity finished..http://stackoverflow.com/questions/14101669/change-brightness-according-to-surrounding-light-in-android/14111181#14111181 – Bhavesh Hirpara Jan 25 '13 at 09:34
  • so don't finish that activity tell android to retain it using flags , you can try something like alwaysRetainTaskState. Also you can put some Timer Task to keep activity seem busy. – android2013 Jan 25 '13 at 09:43
  • Thanks let me try.. My implementation works but I am not getting full brightness when auto brightness is on only. – Bhavesh Hirpara Jan 25 '13 at 09:48
  • What the F***?.. it's having context problem. I just changed `getApplicationContext()` to `getBaseContext()` – Bhavesh Hirpara Jan 25 '13 at 09:56
  • http://stackoverflow.com/questions/6854265/getapplicationcontext-getbasecontext-getapplication-getparent – android2013 Jan 25 '13 at 09:58