Can TabGroup Windows be Locked on Android? - android

My app has a handful of windows. After each of those windows is created, I have code whose intent is to lock those windows in portrait mode:
var win = Ti.UI.createWindow({ ... });
win.orientationModes = [ Ti.UI.PORTRAIT ];
I still can't believe that there isn't a more universal way of doing this for Android, but that's a gripe for another day. :-) For now, this is mostly working. I'm hoping someone here can help me remove the mostly qualifier.
The app opens with a tab group containing 4 tabs. If I rotate my device as soon as the default active tab is loaded, the layout rotates as well. Oops. In fact, if I go immediately to any of those tabs and rotate my device, the layout rotates. More oops.
However -- and this is the fun part -- if I relaunch the app and jump first to a secondary window, one loaded from one of the tab windows, and rotate my phone, no display rotation. Yay! Now I jump back to any of the tab windows, the ones that were rotating before, they no longer rotate.
Wat?!
That's the pattern I think I'm seeing right now. Anyone seen this before? I'm guessing that it's a tab group thing, but I don't see any orientation accessors in the API. Any guidance would be much appreciated.
Thanks.

You'll want to add this to your tiapp.xml
<android >
<manifest>
<application>
<activity android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation">
</activity>
</application>
</manifest>
</android>
That will lock your entire app into portrait mode

Create a custom AndroidManifest.xml through the help of this
and add this line in Application Blog
<application
android:debuggable="false"
android:icon="#drawable/appicon"
android:label="iVite"
android:name="IviteApplication" >
<activity
android:configChanges="keyboardHidden"
android:name="org.appcelerator.titanium.TiActivity"
android:screenOrientation="portrait"/>
<activity
android:configChanges="keyboardHidden"
android:name="ti.modules.titanium.ui.TiTabActivity"
android:screenOrientation="portrait"/>
<activity
android:name="ti.modules.titanium.ui.android.TiPreferencesActivity"/>
</application>
This is right way to use. Because, In Tabbar Application. We have also need to set Tabbar Activity and its orientation Setting. Like in above code In above Code.
Here, both Activity Orientation is set through AndroidManifest.xml.
TabbarActivity and Window Activity.
Cheers....

Related

In AndroidManifest: Expecting android:screenOrientation="unspecified"

Android Studio 3.6.
I want my app to be always in portrait mode. So in my AndroidMainfest.xml:
<activity
android:name=".activity.SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I run the app and SplashActivity shows in portrait mode. Nice.
But the editor shows the following error:
Expecting android:screenOrientation="unspecified"
Why?
In your manifest tag (just under xmlns:android="http://schemas.android.com/apk/res/android"), put
xmlns:tools="http://schemas.android.com/tools"
Then inside the application tag, put
tools:ignore="LockedOrientationActivity"
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
In Android studio 3.6.0 i guess they want the user to handle the orientation and encourage developer to use ViewModel stuff.
Let me explain screenOrientation in detail
android:screenOrientation="portrait"
will give you error you have to either specify
android:screenOrientation="fullSensor" or android:screenOrientation="unspecified"
fullSensor Means either you have ON the "Rotate off" or not it will change the orientation based on you move the phone
unspecified Means if you have ON the Rotate off then it will stay only in that orientation and if not then it will change the orientation based on you move the phone.
Add following line after android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"
Then click Alt+Enter
I found 2 way of solving this problem
First,
Android Studio -> Preferences (for Mac) or Settings (for Windows)
-> Search "chrome"
-> Uncheck "Activity is locked to an orientation"
-> Apply and Ok
-> Sync Project with Gradle file
Second,
Select "Run" from the main menu
-> Edit Configurations.
-> Launch options - Launch
-> Select Nothing or Specified Activity
-> Sync Project with Gradle file
tools:ignore="GoogleAppIndexingWarning,LockedOrientationActivity"
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.
I have faced this issue, In my requirement, some of the activity will support both orientations and remains will keep in portrait, In this case, I resolved by the following steps:
Case-1:- To lock Orientation
Step-1:
Please Add following line Application tag in AndroidManifest.xml
tools:ignore="LockedOrientationActivity"
<application
android:name=".activity.MyApplication"
tools:ignore="LockedOrientationActivity">
Step-2: If you want to lock screen orientation either in portrait or landscape
add the following line in the activity tag
android:screenOrientation="portrait" or "landscape"
Case-2:- Suppose if u want to allow orientation in particular activity and have a specific design for landscape
Step-1:
Remove Orientation value in configchanges and remove screen orientation if it exists from activity tag, and my personal suggestion use (LifecycleObserver) in Activity for without losing values while changing orientation.
android:configChanges="orientation"
android:screenOrientation="portrait" or "landscape"
This is the way I resolve this issue, hope it helps, Thanks & Happy Coding.
Try with below code:
if(MainActivity.this.getResources().getConfiguration().orientation== Configuration.ORIENTATION_PORTRAIT){
MainActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
}
Try putting the following in the activity tag
android:configChanges="orientation"
android:screenOrientation="portrait"

Definition of android device natural orientation

I want to change the basic orientation of an android device. Curently its startup orientation is landscape, I need portrait.
I managed to modify the acceleration values so that the axis now point to where I want them to point to.
But the device seems to have its own definition of up and right. Now I have to change this.
Can someone tell me where this can be done? I guess there is a config file out there that I can't identify.
There are millions of hits searching for this problems. Unfortunately they all deal with java programming, not with OS code.
In your manifest file under activity tag that is on which screen you want to apply that orientation.
For portrait
android:screenOrientation="portrait"
For landscape
android:screenOrientation="landscape"
Add this lines of code in Androidmanifest.xml for the orientation
<activity android:name=".SomeActivity"
android:label="#string/app_name"
android:screenOrientation="landscape">

Unity3D application always launches with same orientation on Android, regardless of OS orientation

When I launches app, it always has same orientation.
After some seconds, maybe in splash scene, it turns to OS orientation.
I got that the orientation always 'Landscape Left' even if device was 'Landscape Right'.
That is my problem.
I expect that app launches so that it matches the orientation of os.
Not portrait or landscape problem, but 'Landscape Left' or 'Landscape Right' problem ;(
PlayerSettings like as bellow.
http://answers.unity3d.com/storage/temp/48453-orientation.png
I set 'Auto Rotation' and checked 'Landscape Right' and 'Landscape Left'.
http://answers.unity3d.com/storage/temp/48455-minsdk.png
And I also set min SDK api level 14.
I set screenOrientation="landscape" in AndroidManifest.xml
<activity android:name="myMainActivity" android:label="#string/app_name" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:icon="#drawable/app_icon" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="landscape" android:launchMode="singleTop">
Im using Unity3d 4.6.6p1
Thanks ;)
You can use this to control the orientation in the device via Code Screen.orientation.
You only need to ask wich are the current orientation and channge it to the other if you need it.
Hope It'll be helpfull to you.

Android always in portrait mode not working

I want to run my application always in portrait mode. I searched and found the code below, then I added to manifest file.
android:configChanges="orientation"
android:screenOrientation="portrait"
but my application still chancing orientation when I press CRTL+F12 on AVD.
How can I force my application always run in portrait mode?
Ps: I tried the code reverse. (Second line first then first line)
Did you add that in the activity element, not the application element?
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" >
</activity>

OpenGL when turning Android Phone

What is it called ( what term should i google) when flipping/tilting the phone, so that the view rotates when running android?
My (OpenGL) application crashes when I do this, are there some certain steps you should do when handling OpenGL when this occures?
Is there something else I might want to think about?
if you don't set the AndroidManifest.xml 's attributes for activities that handle their own rotations, your activity will be restarted, the GL context will be recreated, and at least, any surfaces and buffers that you were using will be invalid.
in my gles 1.1 application, I have the following in my AndroidManifest.xml, which specifies that my application activity wants to live on through keyboard and orientation configuration changes, and that the application supports any orientation, but doesn't want it to change -because I don't want to deal with reloading textures or redoing the game layout (yet)
<application android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:debuggable="true">
<activity android:name="MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation"
android:screenOrientation="nosensor"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The problem is like the configuration change that occurs when the screen orientation change occurs. See Configuration Changes. You might want to tell Android that you will handle the orientation change yourself, via the configChanges attribute.
Some good reading: http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html
You could try searching for "Screen rotation android" or "Screen rotation android OpenGL" since you're trying to do 3D. When the screen rotates the current surface gets destroyed and a new one gets created already accounting for the new screen dimensions.
I'd recommend looking into some sample code just to see the correct way to handle screen rotation, look for "ApiDemos.apk" in Android (it's open sourced by the way), specifically the ones who use GL", all of them handle screen rotation.

Categories

Resources