Reputation: 63
I'm trying to create an application always active (ie never goes in the background), with a button that when is pressed reduces the screen brightness. I state that I'm no expert in programming in Android.
Upvotes: 0
Views: 1413
Reputation: 132992
You can set screen BRIGHTNESS o button click as:
FIRST WAY:
@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>
SECOND WAY:
@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"/>
and finally for other way to set brightness see this post
Upvotes: 1