Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Unity/Android throttles from 1440p to 1080p on mobile and returns Android status bar height of 0?

Discussion in 'Editor & General Support' started by mikejm_, Apr 6, 2022.

  1. mikejm_

    mikejm_

    Joined:
    Oct 9, 2021
    Posts:
    346
    I understand we can usually get the height of the Android status bar with:

    Code (csharp):
    1.         AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    2.         var currentActivity = up.GetStatic<AndroidJavaObject>("currentActivity");
    3.         var windowManager = currentActivity.Call<AndroidJavaObject>("getWindowManager");
    4.         var windowMetrics = windowManager.Call<AndroidJavaObject>("getCurrentWindowMetrics");
    5.         var windowInsets = windowMetrics.Call<AndroidJavaObject>("getWindowInsets");
    6.         statusBarHeight = windowInsets.Call<int>("getStableInsetTop");
    This does seem to work when I am on my Samsung Android phones at 720p or 1080p resolutions. However, once I switch to 1440p resolution, I get strange behaviors.

    1) Screen resolution is throttled at 1440p

    Screen.width will still put out 1080 even when the device is running at 1440p. This suggests to me either Android or Unity is throttling itself to prevent it from running at 1440p. I can confirm the true device resolution with:

    Code (csharp):
    1.         AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    2.         var currentActivity = up.GetStatic<AndroidJavaObject>("currentActivity");
    3.         var windowManager = currentActivity.Call<AndroidJavaObject>("getWindowManager");
    4.         var windowMetrics = windowManager.Call<AndroidJavaObject>("getCurrentWindowMetrics");
    5.         var windowMetricsBounds = windowMetrics.Call<AndroidJavaObject>("getBounds");
    6.         hardScreenWidth = windowMetricsBounds.Call<int>("width");
    This will return 1440 even while Screen.width in Unity says 1080. I do not know why it is being throttled or whether it is by Android or Unity.

    2) Unable to get Android status bar height at 1440p

    Under this circumstance while the device is 1440p and Unity is running 1080, I am also no longer able to get any method for returning the Android status bar height to return. The Android getStableInsetTop as well as the related getSystemWindowInsetTop functions in the above script while under this condition both return as zero. (They usually would give some useful numbers.)

    Questions: Is there any explanation for either issue? Why is Unity/Android throttling the resolution, and is there any way to know if it is Android or Unity doing it? Why can't I get the status bar height at 1440p when this is happening? Is the zero status bar height issue due likely to the throttling issue or unrelated?

    If this does sound like a bug and there is no good reason for it, I can submit a test project that debugs this data out to the screen so you can confirm it. Please let me know if that would help.

    Thanks.