App Launching in Corner For FreeFormWindow Support

130 views Asked by At

I am trying to develop an android app which will launch in center of a ChromeBook. But even though I am setting the gravity to center it is always launching in top left corner. But if I set the gravity to any other place rather than center it works fine. For example if I set the gravity to "top|end", it will launch in top right corner.

Here is my Manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:resizeableActivity="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppTheme">
        <activity
            android:name=".MainActivity"
            android:configChanges="screenSize|smallestScreenSize|orientation|screenLayout">
            <meta-data
                android:name="WindowManagerPreference:SuppressWindowControlNavigationButton"
                android:value="true" />
            <meta-data
                android:name="WindowManagerPreference:FreeformWindowSize"
                android:value="[tablet]" />
            <meta-data
                android:name="WindowManagerPreference:FreeformWindowOrientation"
                android:value="[landscape]" />

            <layout
                android:defaultWidth="720dp"
                android:defaultHeight="480dp"
                android:minWidth="450dp"
                android:minHeight="300dp"
                android:gravity="center"/>

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
1

There are 1 answers

0
Max Klint On

Here is what worked for me:

  1. Drop the <layout> section entirely (or, optionally, only keep the minWidth and minHeight attributes, but drop the defaultWidth, defaultHeight and gravity).
  2. Remove the square brackets from meta-data values. It should be just:
<meta-data
       android:name="WindowManagerPreference:FreeformWindowSize"
       android:value="tablet" />

<meta-data
       android:name="WindowManagerPreference:FreeformWindowOrientation"
       android:value="landscape" />