0
int BrightnesValue= 0;
        try {
            BrightnesValue = Settings.System.getInt(
                    getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
        } catch (Settings.SettingNotFoundException e) {
            e.printStackTrace();
        }
        int SysBackLightValue = BrightnesValue-25;
        android.provider.Settings.System.putInt(getContentResolver(),
                android.provider.Settings.System.SCREEN_BRIGHTNESS,
                SysBackLightValue);

我想使用工具栏上的按钮以编程方式更改系统的亮度,如图所示。这样,第一次点击,亮度降低,第二次点击,亮度恢复到默认值。

4

1 回答 1

1

您可以设置屏幕亮度按钮单击

第一种方式:

@Override
  public void onClick(View arg0) {
   // TODO Auto-generated method stub
   int curBrightnessValue=android.provider.Settings.System.getInt(
       getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS);
   setBrightness(curBrightnessValue-25);//set BRIGHTNESS
  }
private void setBrightness(int brightness) {  
    try {  
      IHardwareService hardware = IHardwareService.Stub.asInterface(  
      ServiceManager.getService("hardware"));  
      if (hardware != null) {  
        hardware.setScreenBacklight(brightness);  
      }  
    } catch (RemoteException doe) {            
    } 

清单.xml

<uses-permission android:name="android.permission.HARDWARE_TEST"></uses-permission>

第二种方式:

@Override
   public void onClick(View arg0) {
   // TODO Auto-generated method stub
   int curBrightnessValue=android.provider.Settings.System.getInt(
   getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS);
   int SysBackLightValue = curBrightnessValue-25;
   android.provider.Settings.System.putInt(getContentResolver(),
   android.provider.Settings.System.SCREEN_BRIGHTNESS,
   SysBackLightValue);
  }

AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
于 2017-05-05T21:33:54.987 回答