How to set android:screenOrientation=“portrait” fo

2019-03-06 01:10发布

I am using Samsung Galaxy Note to run a phonegap application. When I take picture, I can see that screen rotates just before entering camera. How can I disable this?

I have tried to force portrait orientation on both, the main thread & camera activity, but those do not seem to work:

<application android:icon="@drawable/icon" android:label="@string/app_name"
    android:debuggable="true">
    <activity android:name=".App" android:windowSoftInputMode="adjustPan" android:screenOrientation="portrait"
              android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" 
              android:configChanges="orientation|keyboardHidden">
        <intent-filter>
        </intent-filter>
    </activity>
    <activity android:name="com.android.camera.Camera"
            android:screenOrientation="portrait">
    </activity>
</application>

4条回答
劫难
2楼-- · 2019-03-06 01:11

There are 2 things here that should be taken into account. First, this

android:screenOrientation="landscape"

has no effect if in the java code there is something like this:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Then, there is this other method that could be bothering you:

mCamera.setDisplayOrientation(90);

This would rotate your camera preview.

Hope this helps!

查看更多
Anthone
3楼-- · 2019-03-06 01:21

You need to add the permission on the manifest:

<uses-feature android:name="android.hardware.screen.portrait" />

Doc android of balise uses-feature

For example, if your app requires portrait orientation, you should declare <uses-feature android:name="android.hardware.screen.portrait"/> so that only devices that support portrait orientation (whether always or by user choice) can install your app. If your application supports both orientations, then you don't need to declare either.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-03-06 01:25

Use android:configChanges="orientation|keyboardHidden" where you are setting screen as portrait.

查看更多
小情绪 Triste *
5楼-- · 2019-03-06 01:29

How do you take picture? If you are sending intent to fire up camera application you lose control about orientation changes. Also note, that before going to sleep and locking screen launcher forces your application into portrait with an butt-kick regardles of the settings or overriding methods. Most probably you can not and behaviour on other devices could be different.

查看更多
登录 后发表回答