How to enable only portrait and reverse portrait in phones, “sensorPortrait” not working on phones?

∥☆過路亽.° 提交于 2019-12-12 09:37:49

问题


I cant figure out why setting "sensorPortrait" attribute in manifest for an activity doesn't work to allow the activity to go into reverse portrait. This is how I set in manifest

    <activity
        android:name=".MainActivty"
        android:label="Testing"
        android:screenOrientation="sensorPortrait"
        android:windowSoftInputMode="stateHidden"
        android:configChanges="orientation">
    </activity>

The above code is not working for me to get both reversePortrait and portrait on Moto E(4.4.4) or Galaxy S3(4.3), but I can confirm it works on a Nexus 7(5.0.1) tablet, I tried several other answers but this one seems to be the easiest and it is seemingly not working for me on 'phones', am I missing some information that is relevant for getting this to work?

I tried the following link which is just as similar as my question but nothing seems helpful regarding this

Activity in portrait or reverse portrait only

Currently with the flag "sensorPortrait" it behaves just like setting "portrait", in phones.


回答1:


If you look at the PhoneWindowManager source code, you can see that it checks for the internal value config_allowAllRotations and uses that to determine if the 180 degree rotation (i.e., reverse portrait on phones) is allowed.

With a default value to false, this means that reverse portrait is disabled on phones. You'll note that the sw600dp value (i.e., tablets) is true, hence why you can use all rotations including reverse portrait on tablet devices.



来源:https://stackoverflow.com/questions/29079024/how-to-enable-only-portrait-and-reverse-portrait-in-phones-sensorportrait-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!