I am trying to change screen brightness from a widget. Basically, I have followed the suggestion from the following page. Changing the Screen Brightness System Setting Android
So far, this is what I have been able to do. 1. I have a main activity with buttons, when I click on the button, I can change the brightness of the screen.
I have a widget with buttons. I have confirmed that the RefreshScreen class is being called from a widget buttons. I call this class from AppWidgetProvider. Problem The screen brightness does not change. When I run the problem with debug mode, I get the following warnings.
10-21 12:20:21.579: W/BackupManagerService(137): dataChanged but no participant pkg='com.android.providers.settings' uid=10086
10-21 12:20:21.579: W/InputManagerService(137): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40f56aa8
I have the following permission set.
I have the following code to change the brightness. I'm sorry for confusing code but I have two buttons. When Brightness button is changed, the screen is supposed to get the brightest. When Volume button is changed, the screen is supposed to be half way between the darkest and the brightest.
Any input is greatly appreciated. Thank you.
public class RefreshScreen extends Activity {
public static String BRIGHTNESS_VALUE = "BRIGHTNESS_VALUE";
public static String BRIGHTNESS_CHANGE = "BRIGHTNESS_ACTION";
public static String VOLUME_CHANGE = "VOLUME_ACTION";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String value = intent.getStringExtra(BRIGHTNESS_VALUE);
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
if (value.equals(BRIGHTNESS_CHANGE)) {
Toast.makeText(this, "BRIGHTNESS CHANGE Clicked", Toast.LENGTH_LONG).show();
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS, 255);
layoutParams.screenBrightness = 1F;
getWindow().setAttributes(layoutParams);
}
if (value.equals(VOLUME_CHANGE)) {
Toast.makeText(this, "VOLUME CHANGE Clicked", Toast.LENGTH_LONG).show();
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS, 125);
layoutParams.screenBrightness = 0.5F;
getWindow().setAttributes(layoutParams);
}
finish();
}
}