Forum Discussion

SteveYo's avatar
SteveYo
Copper Contributor
Oct 21, 2020

Can't get device real width when app create

Hi all,

When running app on Surface duo, is always create on one screen(1350x1800), not two screen(for me is full screen, 2784x1800).

 

I can't get device real width when app only on one screen, but user usually don't put app on two screen.

I use android api like

WindowManager wm = (WindowManager) MainActivity.this.getSystemService(Context.WINDOW_SERVICE);
Point size = new Point();
wm.getDefaultDisplay().getRealSize(size);

Still not get real device width.

 

So, is there any function can get real device width? or can app start on two screen(full screen)?

 

Thanks for any helpful tip!

 

  • SteveYo apps cannot start on two screens - it is always a user-choice to span. So it will always start on a single screen.

     

    The app can only get the dimensions that it runs in, so Window Manager can only get the 1350x1800 dimensions when the app is one a single screen.

     

    Can you share why you need two-screen width when your app is only running on one screen?

    • SteveYo's avatar
      SteveYo
      Copper Contributor

      Craig_Dunn 

      Hi Sir,
      Thanks for your help.

       

      I would use the screenshot function to take screenshots,
      and do something on this screenshot.

      for example, get icon from screenshot.


      This screenshot is full screen(two-screen) but only 1350x1800 dimensions(one-screen).

      I will get wrong position because wrong dimensions.

       

      Now I know app can only get the dimensions that it runs in(1350x1800 dimensions).
      And is there any function can get real device width(2700x1800 dimensions)?

      Thanks for any helpful tip!

      • Craig_Dunn's avatar
        Craig_Dunn
        Icon for Microsoft rankMicrosoft

        SteveYo I've learned that screen capture apps that use the MediaProjection API are a special case. You need to run a foreground service to capture and have the android:foregroundServiceType="mediaProjection" attribute in the manifest.

        In the media projection foreground service, queries for the DisplayMetrics will get the full display metrics (both screens) - but only in the service, not in any query made from an activity.

        Hope that helps.