Search Unity

Dealing with Samsung S8 insane aspect ratio? How to letter box an app?

Discussion in 'Android' started by 39thstreet, Jan 12, 2018.

  1. 39thstreet

    39thstreet

    Joined:
    Jan 30, 2012
    Posts:
    104
    Our apps are strictly 2d (using 2d toolkit), and are designed to do a combination of scaling and positioning to handle the range of mobile aspect ratios from 4:3 to 16:9. They could even go a little longer, but Samsung S8 is a bewildering 18.5:9(2960x1440).

    Unfortunately, we never anticipated a phone designed to be that long and thin, and our camera overrides/scaling aren't cutting it with the background images. Meanwhile, my camera bottom left/top right anchors have stuff floating over the empty space the background doesn't reach.

    What I need to do is just totally ignore around 400 pixels (preferably leaving it black on either side, or one side, whatever), to bring it down to a reasonable 16:9 (2,560x1,440).

    Is there some easy way to do this without manually recoding all of my anchors? Cross posted on 2dtoolkit forum because wasn't sure if there were any 2dtk tricks that might help.

    Any help would be greatly appreciated :(
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    If you are using Unity 2017.2 or later, go to "Player Settings -> Resolution and Presentation, chose "Custom" as an "Aspect Ratio Mode" and enter 1.86. For older Unity versions you will have to edit Android Manifest. Here's official info on what you'll have to add https://developer.android.com/guide/practices/screens_support.html#MaxAspectRatio (note that you'll want 1.86 or similar values instead of recommended 2.1 or higher).
    Another thing to note is that Samsung phones tend to remember if your app was opened in "full wide screen" and even modifying the manifest may still open them in "full wide screen" (there should be a toggle in settings for each installed app which allows choosing whether the app should use a full screen or just a 16:9 aspect part of it). If you run into this issue, uninstall your app from the device and then install it again instead of doing an app update.
     
    39thstreet likes this.
  4. 39thstreet

    39thstreet

    Joined:
    Jan 30, 2012
    Posts:
    104
    Thanks, that sounds like just what I need.

    So far, doesn't seem to be working when I test though.
    1. I set the PlayerSettings to "Legacy"/186
    2. I copied the androidmanifest into my plugins/android directory and modified it, adding to activity:
    android:maxAspectRatio="1.86" android:resizeableActivity="false"
    AND
    <meta-data android:name="android.max_aspect" android:value="1.86" />

    When I run the app (even on a completely clean install, or a freshly made emulator) it still runs full screen.

    Even more bizarre, when I open the APK in Android studio and view the included AndroidManifest.xml I see this:
    android:maxAspectRatio="1072567424.000000"

    Why would it change from 1.86 to that huge number?!
     
  5. 39thstreet

    39thstreet

    Joined:
    Jan 30, 2012
    Posts:
    104
  6. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    As in my previous response I suggest to use "Custom" (with 1.86 value) instead of the "Legacy". Legacy in this case means "works the same as in old Unity versions" and depending on a few things there might be nothing added to the manifest. On the other hand choosing "Custom" will always specify max aspect ratio in the manifest, but please note that according to android docs (which I've linked previously) different manifest attributes / elements are used depending on Android version. So when you'll set "Custom with 1.86" try building your app with target sdk level lower than 26 and then with 26 or higher (two variants). See if the result will differ when you'll run those versions on the device.
    This should be a valid alternative to using Unity editor Player settings and should work the same.
    Did you run your app on the physical device or only on the emulators? It could be that emulators always scale your app and ignore max aspect ratio values. If possible, I'd strongly suggest to test on the actual physical device.
    I've just tried this and can confirm this is shown in the apkanalyzer tool. However I think this is likely an issue of the apkanalyzer and the number is formatted incorrectly. I'd suggest to do the following: Build the apk with Unity editor and don't close the editor. Go to your project location and inspect the Temp/StagingArea/AndroidManifest.xml file. This is the final version of Android manifest after all manifest merging is done, before it is packed into the apk file.