Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7683571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:49:29+00:00 2026-05-31T18:49:29+00:00

I’m attempting to change the screen brightness from withing a service, like so: android.provider.Settings.System.putInt(getContentResolver(),

  • 0

I’m attempting to change the screen brightness from withing a service, like so:

android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS, bright);

Problem is that is doesn’t work. Well, actually it succeeds in changing the brightness setting, but the screen brightness doesn’t actually change till I go into the phones settings, look at the new value and hit Ok.

Is there something I have to do after setting the value to get the brightness to change?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:49:30+00:00Added an answer on May 31, 2026 at 6:49 pm

    I’ve had the same problem of changing screen brightness from within a service, and a couple days ago i have successfully solved it(and updated my app Phone Schedule with brightness feature 😉 ).
    Ok, so this is the code you put into your service:

    // This is important. In the next line 'brightness' 
    // should be a float number between 0.0 and 1.0
    int brightnessInt = (int)(brightness*255);
    
    //Check that the brightness is not 0, which would effectively 
    //switch off the screen, and we don't want that:
    if(brightnessInt<1) {brightnessInt=1;}
    
    // Set systemwide brightness setting. 
    Settings.System.putInt(getContentResolver(),
    Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
    Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightnessInt);
    
    // Apply brightness by creating a dummy activity
    Intent intent = new Intent(getBaseContext(), DummyBrightnessActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("brightness value", brightness); 
    getApplication().startActivity(intent);
    

    Please Note that in the above code snippet I’m using two variables for brightness. One is brightness, which is a float number between 0.0 and 1.0, the other one is brightnessInt, which is an integer between 0 and 255. The reason for this is that Settings.System requires an integer to store system wide brightness value, while the lp.screenBrightness which you will see in the next code snippet requires a float. Don’t ask me why not use the same value, this is just the way it is in Android SDK, so we’re just going to have to live with it.

    This is the code for DummyBrightnessActivity:

    public class DummyBrightnessActivity extends Activity{
    
        private static final int DELAYED_MESSAGE = 1;
    
        private Handler handler;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);            
            handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    if(msg.what == DELAYED_MESSAGE) {
                        DummyBrightnessActivity.this.finish();
                    }
                    super.handleMessage(msg);
                }
            };
            Intent brightnessIntent = this.getIntent();
            float brightness = brightnessIntent.getFloatExtra("brightness value", 0);
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.screenBrightness = brightness;
            getWindow().setAttributes(lp);
    
            Message message = handler.obtainMessage(DELAYED_MESSAGE);
            //this next line is very important, you need to finish your activity with slight delay
            handler.sendMessageDelayed(message,1000); 
        }
    
    }
    

    This is how you add your activity to the AndroidManifest.xml, probably the most important part:

    <activity android:name="com.antonc.phone_schedule.DummyBrightnessActivity"
                android:taskAffinity="com.antonc.phone_schedule.Dummy"
                android:excludeFromRecents="true"
                android:theme="@style/EmptyActivity"></activity>
    

    A little explanation about what’s what.

    android:taskAffinity must be different, than your package name! It makes DummyBrightnessActivity be started not in your main stack of activities, but in a separate, which means that when DummyBrightnessActivity is closed, you won’t see the next activity, whatever that may be. Until i included this line, closing DummyBrightnessActivity would bring up my main activity.

    android:excludeFromRecents="true" makes this activity not available in the list of recently launched apps, which you definetely want.

    android:theme="@style/EmptyActivity" defines the way DummyBrightnessActivity looks like to the user, and this is where you make it invisible. This is how you define this style in the styles.xml file:

    <style name="EmptyActivity" parent="android:Theme.Dialog">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Toast</item>
        <item name="android:background">#00000000</item>
        <item name="android:windowBackground">#00000000</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:colorForeground">#000</item>
    </style>
    

    This way your DummyBrightnessActivity will be invisible to the user. I’m not shure if all of those style parameters are really necessary, but it works for me this way.

    I hope that explains it, but if you have any questions, just let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.