android:screenOrientation="portrait" ignored on a Nexus 5x running Marshmallow - android

I am getting reports that my supposedly portrait app can be rotated to landscape mode on a Nexus 5X running Marshmallow. I don't have one to test on but why is this happening? Here is my activity in the manifest:
<activity
android:name=".app.MainActivity_"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Activity"
android:launchMode="singleTask"
>
</activity>

Try and change your tragetSDKVersion from Marshmallow to Lollipop.
It worked for me.

You must use this for the Activity!
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
and for the whole application you must use this code which will force the orientation not to be landscape
<application
android:debuggable="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait">

Related

How to enable "resizeableActivity" for only a singe Activity

I am using samsung's foldable device - Galaxy Z Fold3 5G
I need to set resizeableActivity = true of only a single activity.
I cannot set it in main <application> tag as it will be applied to the whole app.
<application
android:networkSecurityConfig="#xml/network_configuration"
android:resizeableActivity="false"
tools:targetApi="n">
.....
.....
</application>
I've also tried writing it in the <activity>, but it is not working there.
<activity
android:name=".PlayVideo_Act"
android:hardwareAccelerated="true"
android:allowTaskReparenting="true"
android:launchMode="singleTask"
android:resizeableActivity="true"
android:screenOrientation="locked"/>
Any help?

Set screen orientation of application in android

Here is my code to set orientation of screen
<activity
android:name="com.srikanth.lullaby.MainActivity"
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name="com.srikanth.lullaby.SoundRecordingActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name="com.srikanth.lullaby.RecorderActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name="com.srikanth.lullaby.MediaplayerExample"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name="com.srikanth.lullaby.MediaPlayerActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
but it is not working properly ,when i rotate the screen then app changing its direction
How to fix this.
Try this..
Just remove
android:configChanges="orientation"
Or in your java add this line after setContentView(R.layout.yourlayout);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Try to add like this for every activity tag:
<activity
android:name="com.srikanth.lullaby.RecorderActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/>
Try this
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
use theme in Application tag
android:theme="#android:style/Theme.Black.NoTitleBar"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation|screenSize"
The android:configChanges line prevents onResume(), onPause() from being called when the screen is rotated. Without this line, the rotation will stay as you requested but the calls will still be made.
keyboardHidden and orientation are required for < Android 3.2 (API level 13), and all three options are required 3.2 or above, not just orientation.

Phonegap Android app reset to main screen each time while orientation change

I am creating the phonegap application for android platform but when i change the orientation it will reset and going back to the main screen each time.
<application android:configChanges="orientation|screenSize|keyboardHidden|keyboard|locale" >
...
<activity
android:name="com.example.myapp.MainActivity"
android:label="#string/app_name">
</activity>
...
</application>
Add android:configChanges under activity tag not in application tag
like :-
<application >
...
<activity
android:configChanges="orientation|screenSize|keyboardHidden|keyboard|locale"
android:name="com.example.myapp.MainActivity"
android:label="#string/app_name">
</activity>
...
</application>

configChanges not recognized by TabHost?

I have a pretty big problem with my TabHost. Although I have declared all of my Activities (Including my TabHost Activity) to ignore orientation and keyboardHidden, if I flip my Phone (Android 4.0) It still recreates the activity.
Here is a shortened version of my Manifest:
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".TabHost"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity1"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" />
<activity
android:name=".Activity2"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" />
<activity
android:name=".Activity3"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" />
</application>
I don't think that the code of the activities would help?!
If it would however, let me know and I'll post it too.
Kind regards
if you are trying to stop the rotation of the screen use following code in your AndroidManifest.xml for each activity.
android:screenOrientation="nosensor"
UPDATE
According to API when using android:configChanges="orientation|keyboardHidden"
"orientation"
The screen orientation has changed — the user has rotated the device.
Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations.
so, if you are targeting API level 13 or higher you gotta specify screen size also.

How to set android:screenOrientation="portrait" for Camera

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>
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.
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.
Use android:configChanges="orientation|keyboardHidden" where you are setting screen as portrait.
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!

Categories

Resources