Change system settings from android widget
I have a widget that changes some of the system settings, but this is not immediate. It looks like I need to update my system settings for this to happen. How can I change some system settings from a widget that runs instantly?
when my widget is clicked it goes to activity with blank background to change system preferences. one of the settings that has been changed is display brightness. this is the code i am using to change display brightness. as soon as I change the settings, I call the completion function to exit the operation, so I am not stuck there after changing the settings. One thing I noticed is that if I didn't get out of the activity, the settings changed, but I was stuck with this activity. its when i added class.this.finish (); to exit an action that does not change the settings.
android.provider.Settings.System.putInt(getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS, brightness); // 0-255
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness / 255.0f;
getWindow().setAttributes(lp);
source to share