简体   繁体   中英

What exactly does android:screenOrientation do in the AndroidManifest.xml?

What does setting android:screenOrientation in the activity of the AndroidManifest.xml actually do?

If I set it, I can still change my screen orientation - so my question is what is its purpose?

I have a Unity game in portrait, that in one section I want to enable rotation - I can do this from Unity without changing the manifest - so it doesn't appear to be preventing me from changing screen orientation - so what is the purpose of it?

Should my game be SensorPortrait , or FullSensor because I enable rotation at one point? What will the difference be?

The docs indicate that it's used for filtering purposes in the Play store, but surely it serves some other purpose?

The android:screenOrientation parameter in the manifest is intended to change the activity orientation.

The reason why it doesn't seem to do anything is because of Unity, it seems. This forum describes a similar problem and solution :

We currently do override the Android manifest with a custom one, which works well in most cases. However, I found that when I try to override the screenOrientation value, it doesn't seem to stick through the build pipeline. At some point, I think Unity overwrites the screenOrientation attribute depending on the PlayerSettings values. Unfortunately though, there doesn't seem to be a PlayerSettings configuration that allows us to use the "userPortrait" setting.

    // as an android plugin through unity
    public static int GetAutorotateSetting(Activity activity)
    {
        int setting = 0;
        try
        {
            setting = Settings.System.getInt(activity.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION);
        }
        catch(Exception e)
        {
            Log.i("Unity", "Couldn't retrieve auto rotation setting: " + e.getMessage());
        }
        return setting;
    }
    // on the unity side:
    public static bool AllowAutorotation()
    {
        bool doAutorotation = false;
    #if !UNITY_EDITOR && UNITY_ANDROID
        AndroidJavaClass unity = newAndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject unityActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
     
        using(AndroidJavaClass andClass = new AndroidJavaClass("PUT YOUR JAVA CLASS HERE"))
        {
            int allowAutorotation = andClass.CallStatic<int>("GetAutorotateSetting", unityActivity);
            if(allowAutorotation == 0)
            {
                doAutorotation = false;
            }
            else
            {
                doAutorotation = true;
            }
        }
    #endif
        return doAutorotation;
    }

The person who suggested this solution also put a .unitypackage file on github .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM