how can i change application brightness? I know this method
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = (value);
getWindow().setAttributes(layoutParams);
BUT, this method can change just view (activity) brightness, I want to change brightness for all activities in my application. How can I do it?
Also I do not want to change system brightness manually!! So just brightness for all activities JUST in my application.
Thank you for your answers!
I'm not sure there's an easy way to do that. I would save the brightness value the device is on when the user launches the app, then set the brightness to whatever value you want, and reset the brightness to the initial saved value when the user exits the app.
Related
I am designing a game in which the player has to change the brightness of his phone in order to pass to the next level.
The idea I have is that there might be an android-permission to allow detect a change in the brightness level.
So my question is that how do I use it in my app.
Thanks in advance.
Is it possoble to rotate the whole android userinterface on an eventlistener ?
For example an app which runs in the background and after putting the headphones in the whole interface turn 180° until you put it out again.
Yes it is possible to change layout programmatically (Although not sure about 180 degrees?).
See this link: Change Screen Orientation programmatically using a Button
The first answer he has explained how to change layout programmatically instead of setOnClickListner you can use your eventListener.
EDIT: Look at this:
https://developer.android.com/reference/android/content/Intent.html#ACTION_HEADSET_PLUG
Its the broadcast which takes place in the event a headset was plugged in.
I want to change system brightness to the maximum when an activity is launched.
I use following examples but they didn't work properly .
Also the system brightness shouldn't change when an application is running.
Change the System Brightness Programmatically
changing screen brightness programmatically in android
How could I achive this process . Any ideas about this ?
Thank you.
You can use this :
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = (float)WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL;
getWindow().setAttributes(lp);
You should note that this method doesn't change system settings, and the brightness will be back to normal once the activity is paused or destroyed,
Honestly, I don't remember how to change system settings' brightness, but once I find it out,I will post another answer.
If you want to change brightness back to normal then replace BRIGHTNESS_OVERRIDE_FULL with BRIGHTNESS_OVERRIDE_NONE.
Hope this helps :D
I am making a widget that changes system screen brightness on click.
I did it like on this post
Everything works well, but changings brightness takes approximately 1 second, but I want to change it immediately, like it does default android widget.
How can I do it?
I feel like this question is similar, correct me if I'm wrong
Changing screen brightness programmatically (as with the power widget)
I have a button which is basically used for start/stop. So initially the text of the button is set to start. I attached a OnClickListener to it. So whenever it gets clicked i change its text. So if it was start it become stop and vice-versa.
The problem comes when i change my phone view from portrait to landscape or vice-versa the button text gets reset.
So for example I clicked the start button---it changed to stop. Now if I tilt my phone to change the view the button text gets set to start again.
Am I using the button in a wrong way?
You should save your button state. When screen orientation changes, onCreate is called and all your app variables are re-intitialized. Read more here http://developer.android.com/reference/android/app/Activity.html
No, you are using the button in the right way.
The thing what you are seeing is "configuration change". When you are tilting your device, Android recreating your activity and recreating all it's views (so, they getting default captions as them described in XML).
You need to do the
disable configuration changes for your Activity. To do so, add the following to your manifest's activity tag: android:configChanges="orientation|keyboardHidden". It is not suitable, if you have different layouts for landscape and portraint orientations, when you need to...
handle the configuration changes by overriding onSaveInsatnceState method of your Activity, save a state there and then use it in onCreate method.
See this article for further explanation