In AndroidManifest: Expecting android:screenOrientation=“unspecified”

前端 未结 11 864
隐瞒了意图╮
隐瞒了意图╮ 2021-02-02 04:59

Android Studio 3.6.

I want my app to be always in portrait mode. So in my AndroidMainfest.xml:



        
相关标签:
11条回答
  • 2021-02-02 05:50

    it only affects Android Studio 3.6+

    What is the Issue here? This issue occurs because android framework wants user to control the app orientation himself it is not advised to restrict your app orientation for example if a user wants to use the app in landscape orientation he just flips the device and sensors will do the work but when a developer restrict screen orientation, even when rotation sensor works app will stay in pre-defined state, in a way you are restricting user's device capabilities.

    What to do now? You have two options., First is to ignore the error as it won't cause any build failure even I am doing the same and apk/aab generation is as usual Another Option is to provide Landscape Layouts or to handle the rotation like in some apps which recognize if orientation gets changed they will prompt the user to change the orientation as the app is not supported in such orientation

    It may change in future => at present it is not effecting our build process but it might change in future

    0 讨论(0)
  • 2021-02-02 05:51

    Try This Solution:

    AndroidMainfest :

    <activity
        android:name="com.ui.activity.SplashActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    Hope this helps!

    0 讨论(0)
  • 2021-02-02 05:55

    you can use this code:

    if(MainActivity.this.getResources().getConfiguration().orientation== Configuration.ORIENTATION_PORTRAIT){
            MainActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
        }
    
    0 讨论(0)
  • 2021-02-02 06:00

    I found 2 way of solving this problem

    First,

    Android Studio -> Preferences (or settings in Windows)
    -> search "chrome" 
    -> Uncheck "Activity is locked to an orientation" 
    -> apply and ok 
    -> Sync Project with Gradle flie
    

    Second, `

    Select "Run" from the main menu 
    -> Edit Configurations.
    -> Launch options - Launch
    -> select Nothing or Specified Activity
    -> Sync Project with Gradle file
    
    0 讨论(0)
  • 2021-02-02 06:03

    I have used the below Procedure. It works perfectly for me. In Android studio 3.6.0 I think they want the user to handle the orientation and encourage the developer to use ViewModel stuff. Use the below Procedure to ignore that.

    Firstly Add :

    xmlns:android="http://schemas.android.com/apk/res/android"
    

    in the manifest tag.

    Secondly, Add

    tools:ignore="LockedOrientationActivity" 
    

    in application tag. Happy Coding.

    0 讨论(0)
提交回复
热议问题