2014-01-30 10 views
2

내 앱에서 화면 밝기를 제어하는 ​​SeekBar을 추가했습니다. 그것은 잘 작동합니다. 기기의 화면 밝기를 Oncreate()으로 설정하고 SeekBar의 진행 상태를 설정합니다.화면 밝기 검색 표시 줄이 작동하지 않습니다.

그러나 seekbar 진행률을 변경할 때 장치를 멈추고 장치를 다시 작동시켜야 다시 탐색 할 수 있습니다.

내 코드가 무엇입니까. 나는 내가 그 장치를 알게

brightnessscrollbar.setOnSeekBarChangeListener(

      new OnSeekBarChangeListener() { 

    @Override 

    public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { 
     // TODO Auto-generated method stub 

    BackLightValue = (int) ((float)arg1/100);   
     WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); 
     layoutParams.screenBrightness = BackLightValue; 
     getWindow().setAttributes(layoutParams); 
    } 
    @Override 
    public void onStartTrackingTouch(SeekBar arg0) { 
    } 
    @Override 
    public void onStopTrackingTouch(SeekBar arg0) { 

     int SysBackLightValue = (int)(BackLightValue * 255); 
     android.provider.Settings.System.putInt(getContentResolver(), 
       android.provider.Settings.System.SCREEN_BRIGHTNESS, 
       SysBackLightValue); 
     } 
}); 

답변

4

다음 코드,

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

      brightnessscrollbar.setProgress(BackLightValue); 

      System.out.println("Baclightvalue is "+BackLightValue); 


     } catch (SettingNotFoundException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

seekbarclicklistener이

제로 그래서 내가 준 값에 걸리면 한 oncreate() 나에게

도와주세요 조건으로 onProgresschanged을 (를)

public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { 
    // TODO Auto-generated method stub 

BackLightValue = (int) ((float)arg1/100);  

    if(arg1>5){ 
    WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); 
    layoutParams.screenBrightness = BackLightValue; 
    getWindow().setAttributes(layoutParams); 

    } 
} 
0으로 설정

이제 매력처럼 작동합니다.

0
 public void onProgressChanged(SeekBar seekBar, int progressValue, boolean fromUser) { 
      progress = progressValue; 
      if(progress <1) { 

       progress = 1; 

      } 
      android.provider.Settings.System.putInt(getActivity().getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE, android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); 

      android.provider.Settings.System.putInt(getActivity().getContentResolver(), 
        android.provider.Settings.System.SCREEN_BRIGHTNESS, 
        progress); 


      WindowManager.LayoutParams layoutParams = window.getAttributes(); 
      layoutParams.screenBrightness = progress/(float)255; 
      window.setAttributes(layoutParams); 
     }