Reading Screen Dimension in Android Immersive Mode

Been doing a lot of searching for this and yet to fix my issue. Basically when the phone is in immersive mode (which works fine) then I can’t find a way of getting the true resolution and at a complete loss.

As an example I have an Xperia E1 that should be 480, 800 however all methods I know of reading the screen sizes return 480, 744 which is a huge problem for our game.

What I have tried:

Screen.currentResolution
Screen.width and height
Screen.resolutions (returns nothing as expected)

and even the fancier:

 using(
            AndroidJavaObject metricsInstance = new AndroidJavaObject("android.util.DisplayMetrics"),
            activityInstance = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity"),
            windowManagerInstance = activityInstance.Call<AndroidJavaObject>("getWindowManager"),
            displayInstance = windowManagerInstance.Call<AndroidJavaObject>("getDefaultDisplay")
            )
{
 displayInstance.Call("getMetrics", metricsInstance);
 debugLabel.text += "Test: " + metricsInstance.Get<int>("heightPixels") + ", ";
                debugLabel.text += metricsInstance.Get<int>("widthPixels");
}

But sadly all the methods return the ‘wrong’ resolution, 744 in this case. I have tried this on other 4.4 devices (at least 3) and they all have the same issue. If I manually set the resolution, in this case with height back to 800, everything works as I would like so I am extremely confused!

Anyone any ideas or suggestions? Suprised no one seems to be talking about this!

Ok so figured out half of my issue. I can get the real size by calling this:

        using(AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"), metricsClass = new AndroidJavaClass("android.util.DisplayMetrics"))
        {
            using(AndroidJavaObject metricsInstance = new AndroidJavaObject("android.util.DisplayMetrics"),
            activityInstance = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity"),
            windowManagerInstance = activityInstance.Call<AndroidJavaObject>("getWindowManager"),
            displayInstance = windowManagerInstance.Call<AndroidJavaObject>("getDefaultDisplay"))
            {
                displayInstance.Call("getRealMetrics", metricsInstance);
                currentAR = metricsInstance.Get<int>("widthPixels") / (float)metricsInstance.Get<int>("heightPixels");
            }
        }

And for 4.4 phone with immersive mode this works! :smiley: But… I have a phone (Xperia SP) thats 4.1.2 and it has an annoying bar at just the bottom so now need to figure out a way around that now…

P.S note that the change is to use “getRealMetrics” instead of just “getMetrics”

Edit
Found how to distinguish between the resolutions now. Basically if the API is 19 or above emmersive mode is enabled. To find out the API you can run this:

string os = SystemInfo.operatingSystem;//this is the whole OS string with a big of info

        int position = os.IndexOf("API-");//first grab the start of where we see this label

        string numbers = os.Substring(position + 4, 2);//basically grab the next two characters which are the API numbers
        int test = Int32.Parse(numbers);//now we have an API number