settings - Can't apply system screen brightness programmatically in Android -


i'm using following set system auto brightness mode , level:

    android.provider.settings.system.putint(y.getcontentresolver(),settings.system.screen_brightness_mode, 0);     android.provider.settings.system.putint(y.getcontentresolver(),settings.system.screen_brightness, y.brightness1); 

i can change auto-brighess on , off, , set different levels. settings seem applied -- can go settings --> display --> brightness, , whanever setting set shown correctly. however, actual screen isn't changing brightness. if tap on slider in display settings, gets applied.

i shoudl mention i'm running app withat main activity, , these settings getting applied in broadcastreceiver. did try create dummy activity , tested stuff there, got same results.

ok, found answer here: refreshing display widget?

basically, have make transparent activity processes brightness change. what's not mentioned in post have do:

settings.system.putint(y.getcontentresolver(),settings.system.screen_brightness_mode, 0); settings.system.putint(y.getcontentresolver(),settings.system.screen_brightness, brightnesslevel);  

then

windowmanager.layoutparams lp = getwindow().getattributes();     lp.screenbrightness = brightness;      getwindow().setattributes(lp); 

and if call finish() right after applying changes, brightness never change because layout has created before brightness settings applied. ended creating thread had 300ms delay, called finish().


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -