用于管理屏幕亮度的按钮

时间:2012-05-12 18:54:35

标签: android android-layout android-intent android-widget

我正在尝试创建一个始终处于活动状态的应用程序(即永远不会进入后台),按下按钮会降低屏幕亮度。我声明我不是Android中的编程专家。

1 个答案:

答案 0 :(得分:1)

您可以将屏幕BRIGHTNESS o按钮设置为:

第一种方式:

@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) {            
    } 

的Manifest.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"/>

最后以其他方式设置亮度,请参阅this post