Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by LaireonGames · Mar 17, 2015 at 03:31 PM · androidresolutionscreen

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!

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pako · Mar 17, 2015 at 04:49 PM 0
Share

$$anonymous$$aybe you should file a bug report to Unity.

avatar image LaireonGames · Mar 17, 2015 at 04:51 PM 0
Share

I am considering it but thought it best to post here first to see if anyone can shed light on this

avatar image pako · Mar 17, 2015 at 05:08 PM 0
Share

Actually, I did some quick research and apparently the problem is with Android not Unity. Check this out:

http://stackoverflow.com/questions/20555083/android-gl-screen-size-in-immersive-mode

avatar image LaireonGames · Mar 17, 2015 at 05:17 PM 0
Share

Your right this looks exactly like my issue thanks. When i was searching I skipped traditional Android stuff since I have never done natvie development and most of it means nothing to me :P

Still leaves me a bit stumped, anyone know if we can access things such as:

Display.getRealSize();

Guessing I would have to contact Unity for that though :(

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by LaireonGames · Mar 18, 2015 at 02:55 PM

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! :D 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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pako · Mar 18, 2015 at 03:03 PM 0
Share

Android Immersive $$anonymous$$ode won't work on 4.1.2 because it's available since 4.4:

https://developer.android.com/training/system-ui/immersive.html

avatar image LaireonGames · Mar 18, 2015 at 03:05 PM 0
Share

Yeah exactly so thats a separate issue now. Thus answer accepted to original problem :P

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I support FHD+ Resolution in Android game? 0 Answers

Huawei P20 Pro Safe Area Issue 1 Answer

Finding Screen Resolution of an Android Device 0 Answers

Divide resolution and stretch to screen/window/canvas 1 Answer

How do I set an Android applications resolution? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges