Search Unity

How turn On/Off android display backlight using C#

Discussion in 'Android' started by Muckel, Sep 30, 2017.

  1. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    471
    Someone 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.

    Code (CSharp):
    1. public void CheckScreenBrightness()
    2. {
    3.      using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    4.      {
    5.          var context = actClass.GetStatic<AndroidJavaObject>("SCREEN_BRIGHTNESS");
    6.          AndroidJavaClass systemSetting = new AndroidJavaClass("android.provider.Settings$System");
    7.  
    8.          var screenbrightness = systemSetting.CallStatic<int>("getInt", context.Call<AndroidJavaObject>("getContentResolver"), "SCREEN_BRIGHTNESS");
    9.        
    10.          Debug.Log("Screen Brightness = " + screenbrightness);
    11.      }
    12. }
     
  2. emathew

    emathew

    Joined:
    Jul 31, 2017
    Posts:
    13
    Were you able to find a solution? I am having a similar issue.