0

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

4

1 回答 1

1

您可以将屏幕亮度 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) {            
    } 

清单.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"/>

最后,对于其他设置亮度的方法,请参阅这篇文章

于 2012-05-12T19:01:24.800 回答