android:screenOrientation 在 AndroidManifest.xml 中究竟做了什么?

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

AndroidManifest.xml 的 activity 中设置 android:screenOrientation 到底有什么作用?

如果我设置它,我仍然可以改变我的屏幕方向 - 所以我的问题是它的目的是什么?

我有一个纵向的 Unity 游戏,在其中一个部分我想启用旋转 - 我可以在不更改清单的情况下从 Unity 执行此操作 - 所以它似乎并没有阻止我更改屏幕方向 - 所以它的目的是什么?

我的游戏应该是 SensorPortrait 还是 FullSensor 因为我在某一点启用了旋转?会有什么不同?

docs 表明它在 Play 商店中用于过滤目的,但它肯定还有其他用途吗?

清单中的 android:screenOrientation 参数旨在更改 activity 方向。

之所以好像没有做任何事情,似乎是因为Unity。 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;
    }

提出此解决方案的人 also put a .unitypackage file on github