2012-08-17 2 views
2

나는 프로그래밍 방식으로 안드로이드 장치의 밝기를 설정할 앱을 만들려고합니다. 나는 다음과 같은 코드를 사용하여 현재 시스템의 밝기 값을 검색해야현재 시스템 검색 방법 안드로이드의 화면 밝기 값은 무엇입니까?

BackLightValue = (float)arg1/100; 
BackLightSetting.setText(String.valueOf(BackLightValue)); 

WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); 
layoutParams.screenBrightness = BackLightValue; 
getWindow().setAttributes(layoutParams); 

: 나는 다음과 같은 코드를 사용하여 장치의 밝기를 변경 관리 한 때 코드 위

try { 
    BackLightValue = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS); 
} catch(Exception e) {} 

밝기하지만 나에게 현재의 설정 값을 제공해야 앱을 시작하면 기본값이 50 %로 표시됩니다.

무엇이 잘못 되었나요?

답변

4

이것은 screenBrightness를 -1로 설정하면 밝기가 현재 시스템 밝기 레벨로 설정되므로 올바른 동작입니다.

int curBrightnessValue = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS,-1); 

매니페스트 파일의 사용 권한.

<uses-permission android:name="android.permission.WRITE_SETTINGS" /> 
+0

답장을 보내 주셔서 감사합니다. –

+2

글쎄, 당신은'getInt()'를 호출 할 권한이 필요 없다. 'putInt()'를 호출하고 싶을 때만 필요하다. –

관련 문제