How turn On/Off android display backlight using C# only in Unity3d
Anybody knows how to turn On/Off android display backlight using C# only in Unity? I don't like plugins, and I don't want to make one of my own. I know that you can disable the display while using the proximity sensor... but i don't know how to do it in C# in Unity3d...
Maybe the android.provider.Settings.System.SCREEN_BRIGHTNESS will help but i don't know how to change the value (1-255) in Unity3d with C# If someone have a solution i would be very happy. thank you
here is my code.... but it doesn't work as expected... also i like to know how to set the SCREEN_BRIGHTNESS using C# and Unity... if someone has a working example script or know how to change this... plz help out... many many thx M.
public void CheckScreenBrightness()
{
using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
var context = actClass.GetStatic<AndroidJavaObject>("SCREEN_BRIGHTNESS");
AndroidJavaClass systemSetting = new AndroidJavaClass("android.provider.Settings$System");
var screenbrightness = systemSetting.CallStatic<int>("getInt", context.Call<AndroidJavaObject>("getContentResolver"), "SCREEN_BRIGHTNESS");
Debug.Log("Screen Brightness = " + screenbrightness);
}
}
Answer by Riskjockey · Mar 27, 2019 at 08:52 AM
You can control Android (and iOS) screen brightness using Dimmer: https://assetstore.unity.com/packages/tools/integration/dimmer-141555
One of our apps needed to brighten up the screen when it needed attention after sitting idle for a while, and I figured I wasn't the only one who could use this functionality so I built Dimmer. You can use it to darken the screen too, of course. And it doesn't require any extra Android permissions.
Some example code (just to show usage):
public Dimmer dimmer;
void Update()
{
dimmer.brightness = 0.5f; //brightness ranges from 0 - dark, to 1 - bright
}
Hope you find it useful.