How turn On/Off android display backlight using C# only in Unity3d

924 Views Asked by At

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 M.

1

There are 1 best solutions below

1
On

i've try'ed this but i did not get any result...

   public void CheckScreenBrightness()
{
    using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    {
        var context = actClass.GetStatic<AndroidJavaObject>("SCREEN_BRIGHTNESS");
        AndroidJavaClass systemGlobal = new AndroidJavaClass("android.provider.Settings$Global");

        var screenbrightness = systemGlobal.CallStatic<int>("getInt", context.Call<AndroidJavaObject>("getContentResolver"), "SCREEN_BRIGHTNESS");

        Debug.Log("Screen Brightness = " + screenbrightness);
    }
}