1

here's my code to change the brightness settings of my phone.

After running the app, if I go to the settings>display>brightness of my phone, I see the value changed however not 'updated'. So when I click on the dialog box's ok/cancel button, that's when it gets updated. So am I missing a call that finally after changing the values will update the screen brightness? Thanks.

The code is in C# though, I am using Xamarin and monodroid to develop my App. Thanks people!

Android.Provider.Settings.System.PutInt(ContentResolver, Android.Provider.Settings.System.ScreenBrightnessMode, 0);
int brightnessInt = (int)(1.0 * 255); //To set max brightness

Android.Provider.Settings.System.PutInt(ContentResolver, Android.Provider.Settings.System.ScreenBrightness, brightnessInt);

View v = Window.DecorView.FindViewById(Android.Resource.Id.Content);
v.Invalidate();
Parikksit Bhisay
  • 163
  • 1
  • 5
  • 20

1 Answers1

0

Make sure it's not on auto adjust

Android 2.2: Adjusting screen brightness

The last few lines solve your problem.

Also make sure android:minSdkVersion is at least v 2.3.3

Community
  • 1
  • 1
SteveKB
  • 190
  • 6
  • The first line of code switches the phone to MANUAL mode of brightness. I confirm it is switching to that. I have the target API as 4.2, however, I have to target 2.3 The next in the list after 2.3 is 3.1 Is there a way to get 2.3.3 too? – Parikksit Bhisay Jul 29 '13 at 19:41
  • if you've already set the target api is 4.2 that's fine but the android:minSdkVersion needs to be 2.3.3(which is "10") according to that source. I wrote the wrong thing and I'll edit it. – SteveKB Jul 29 '13 at 20:05
  • I also tried starting a dummy activity. That doesn't work either. :( Yes, the min target version is 4.2 right now. – Parikksit Bhisay Jul 29 '13 at 20:17
  • I'll try making one myself and see if I can find a solution :C – SteveKB Jul 29 '13 at 20:28
  • I am trying to look into this, might help https://bitbucket.org/gyrussolutions/yaab/src Thanks for looking into this! :) – Parikksit Bhisay Jul 29 '13 at 21:10
  • I opened your app up and I don't seem to be seeing the problem. what phone are you using? I'm using a samsung galaxy s3. – SteveKB Jul 29 '13 at 21:45
  • I am using an S2 with an android version 4.0.4 – Parikksit Bhisay Jul 29 '13 at 21:55
  • Hold on, the link that I gave, that isn't my app omg. That is just an example I am looking at. Its an opensource app. – Parikksit Bhisay Jul 29 '13 at 21:55
  • oh I was wondering why I couldn't find the code in the question there. Sorry about that. – SteveKB Jul 29 '13 at 22:02
  • I noticed that in the source you posted the checks for adjusting brightness were wrapped in a synchronize statement. try seeing if that works if you haven't already – SteveKB Jul 30 '13 at 00:38
  • Noope, couldn't find that wrapper in C# – Parikksit Bhisay Jul 30 '13 at 15:20
  • it seems to have a different name http://msdn.microsoft.com/en-us/library/ms173179.aspx – SteveKB Jul 30 '13 at 15:24
  • Got the answer: The problem is, I was doing this in a method, I only had to now call that method using RunOnUiThread(()=>methodName()); Thank you so much for looking into it! :) – Parikksit Bhisay Jul 30 '13 at 16:21
  • ah thanks and sorry I couldn't figure it out exact at first. good luck on building more things with android! :D – SteveKB Jul 30 '13 at 17:08