2

i work about application how can change android screen brightness, can somme help me by giving some examples of how to doing this.

Thanks :-)

user820688
  • 719
  • 2
  • 13
  • 27

2 Answers2

0

You can use android settings for brightness.

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

for manualy settings which takes(0-255) as progress and

android.provider.Settings.System.putFloat(getContentResolver(),
                AppConstant.SCREEN_AUTO_BRIGHTNESS_ADJ, progress);

for automatic settings which takes(-1to 1) as progress

user3207655
  • 188
  • 2
  • 15
0

This peice of code will set the brightness:

private void setBrightness(int brightness) {
    try {
        IHardwareService hardware = IHardwareService.Stub.asInterface(
            ServiceManager.getService("hardware"));
        if (hardware != null)
            hardware.setScreenBacklight(brightness);
        } catch (RemoteException doe) {          
    }        
}

Do not forget to add to your manifest

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

Please check this full example

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106
  • 1
    Hey Sherif, thanks for answer, but i can not download hardwar.jar, where i can find it or the source. – user820688 Nov 09 '11 at 09:21
  • you do not need to download any jar file. Just add this code and maybe you forgot to add the permission (check the answer I edited it) – Sherif elKhatib Nov 09 '11 at 09:27
  • But i have error when import android.os.IHardwareService and import android.os.ServiceManager; and i can't compile – user820688 Nov 09 '11 at 09:34
  • @user820688 I am sorry... Yes you are right. please check http://code.google.com/p/batterywidget/source/browse/trunk/a_batterywidget/?r=9 ... there is a file called 'hardware09.jar" I hope it has all the classes needed – Sherif elKhatib Nov 09 '11 at 10:11
  • Not working , I have test in on android 2.2 , giving me an error " java.lang.NoSuchMethodError: android.os.IHardwareService.setScreenBacklight" , I have included the jar. – Ahmed Oct 09 '12 at 14:24