1

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.

MadMac
  • 11
  • 2
  • Read the Unity's doc about `AndroidJavaObject` and `AndroidJavaClass` then try to port that Java code to C# with the classes I mentioned above. If you run into issues, edit your question, add the Java code you trying to port then add the C# code you wrote with `AndroidJavaObject` and `AndroidJavaClass` that didn't work. You will get help from many Unity users here otherwise it looks like you waiting for someone to do the work for you. – Programmer Sep 28 '17 at 06:19

1 Answers1

0

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);
    }
}
MadMac
  • 11
  • 2
  • 1
    take a look at https://forum.unity.com/threads/how-to-get-property-from-settings-system.458807/, maybe it will help – Petr Jan 27 '21 at 14:12