해당 App이 실행하는 동안에 적용되는 밝기 조절

개발 이야기/Android 2017. 6. 20. 14:44
현재 실행하는 App 의 화면 밝기 조절 코드이다.
App이 종료되면, 이전 밝기 값으로 바뀐다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    public void setWindowBrightness(ContentResolver resolver, Window window){
 
        int bright = -1;
 
        try{
            bright = android.provider.Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS);
        }catch(Exception e){
 
        }
        
        /*
        BRIGHT_MINIMUM = 178.5f;
        bright는 0 ~ 255 사이의 값.
        이 예제의 경우 화면 밝기를 70% 이하인 경우를 가정.
        */
        if(bright > -1 && bright < BRIGHT_MINIMUM){
            WindowManager.LayoutParams lp = window.getAttributes();
            lp.screenBrightness = 0.7f; //70% 로 설정
            window.setAttributes(lp);
        }
    }
cs



간단하게 Activity 내에서 적용해보았다.


1
setWindowBrightness(getContentResolver(), getWindow());
cs

s

쉽다!

'개발 이야기 > Android' 카테고리의 다른 글

Android FFmpeg 빌드  (0) 2019.01.30
SMS Retriever API 사용 예제  (0) 2019.01.30
BroadcastReceiver Wifi 상태 및 신호 세기 변화 감지  (0) 2017.06.20