I am trying to force the App into Landscape by using
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE);
in onResume in a Fragment and set it again to
SCREEN_ORIENTATION_UNSPECIFIED
in onPause so it is only in landscape for this fragment.
This works fine when screen orientation is not locked. But as soon as i lock the screen orientation in android the whole device crashes.
I have testet it with differenet devices and found that it works fine even if orientation is locked on a Nexus 6.
But on my Galaxy S8 it completly crashed.
Also on xiaomi mi mix it the App crashed but the device didn't.
Does anyone know a way around this?
This is what my phone looks like after a few seconds.
Related
I am working in an android project targeted for Samsung Galaxy Tab E in Landscape.
The android application starts on boot(as per requirement), after booting, Android by default loads in portrait and switches to Landscape quickly.
The app is already started(Though screen is locked), but the working area in app would be only the width equal to the width in portrait.
This issue appears when screen is locked and orientation of tablet is set to Landscape.
With reference of attached picture in link https://i.stack.imgur.com/4K5Ul.png.
P : is screen when in portrait.
L : is screen when in Landscape.
A : is working portion of L (Whose width is equal with width in portrait mode)
B : is NON-working portion of landscape.
This issue is resolved, and I have explained my case and solution which might be useful for other developers with similar issue.
The issue was not with android application itself. The issue was because android starts my application before boot completion. In my project, android app would run in accessory mode, controlled from another device.
Once the external device gets tablet during restart/power on, my android application starts to run before boot completion, I made another application (app of external device) which sends request to accessory device to sleep for a while when new device is found, so that tablet has enough time to boot and can start app.
Thank you!
I painfully found out today that
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
Does not work properly on the latest Samsung devices.
I want to be able to set screen orientation by the state of the sensor, meaning that even if the device has portrait only set (on device level), if the user rotates the device to landscape my app should change configuration - Reload activity with the proper layout.
SCREEN_ORIENTATION_FULL_SENSOR works fine on any other device, and on old Samsung devices. New Samsung devices do all sort of crazy layout behaviour with that setting.
My app has 3 screens, and all of them must be portrait-only in smartphones and both orientation for tablets.
Unitl now I was using the following code in OnCreate:
if (!getResources().getBoolean(R.bool.isTablet)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
However if I hold the smartphone in landscape mode and launch the application it will show in landscape for a few seconds then rotate to portrait.
Many answers here suggest locking orientation via manifest, but that would lock the orientation in tablets, which is not desired.
I would be very grateful for any information that leads me to a solution. Thanks.
You could lock it in the Manifest and then unlock it in code if it's a tablet.
It may not matter for your case, but I've read that the Nexus 7 doesn't report itself as a tablet using the method you do. I'm not sure that's accurate though, never having tried it myself.
Testing my application on my Galaxy S2 I have a problem whenever the screen is turned off and back on. My application is locked into landscape by the manifest. The lock screen forces the application into some weird orientation where it is rendering portrait but displaying it was landscape (as in the right 2/5 of my screen is black and the portrait rendering goes off the bottom). The application is also not responsive in this state. If I quickly hit home (or back) and recall the application it works perfect.
As well, if I use a different lock screen (tried with PowerAmp) it works flawlessly.
So can anyone help me understand why this is screwing up and how to fix the orientation whenever this happens?
I can avoid this by avoiding the lock screen through a flag (window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)) but I don't have any other reason to avoid a lock screen and would like to know what is happening.
This sound like a problem that is unique to the S2. Have you tried your app on the emulator or any other devices. It may just be that the S2 implements some part of android incorrectly.
To handle the orientation problem in your application try to use this for your activity like this
<activity android:configchanges="orientation|keyboardHidden" />
in your Android Manfiest file.
I have an android application that I want to always be running in landscape mode.
I have the following code implemented to keep the app in landscape mode all the time:
inside my activity in the Application Manifest
android:screenOrientation="landscape"
This seems to launch and keep the application in landscape view for the whole duration of the application. Perfect!
However, if I have the app running on my HTC Aria (Android 2.1) and the phone locks, if I unlock the phone, I see the application for probably half a second and it's in portrait orientation and then quickly switches back to landscape mode. It is quite frustrating because all of my views are jumbled around and it looks unprofessional as you can imagine. This happens in both the emulator and on my real phone.
Does anyone know how to stop the application from temporarily rotating when the phone is unlocked?
Additions:
I have tried overriding onConfigurationChanged() but with no success.
I have also tried putting setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); into the onResume() but the app still shows as the incorrect orientation for a split second when the phone is unlocked.
Try setting the orientation in the manifest file. it might just work.
After looking at many other apps that are made for landscape orientation only, I can see that their apps don't freeze their orientation after standby either. I have a feeling that this is a limitation of the phone, and that all apps will switch to a portrait orientation when the phone is locked. If all apps have this "problem" then I think it is acceptable not to fix.
Please post if you have found out there is a way to stop the forced portrait orientation.
the app still shows as the incorrect orientation for a split second when the phone is unlocked.
Did you move setContentView(R.layout.main) to the onResume, AFTER where you put your orientation code? I would try setting the orientation, then the setContentView()