Getting the natural orientation of a device in CN1 - android

Is there a method to check the natural orientation of a device's screen in Codename One? Meaning, the default orientation regardless of the device's current rotation or current orientation. (e.g. the result should be on a galaxy tab: landscape, on a galaxy phone: portrait)
Note: Comparing getDisplayWidth/getDisplayHeight is not expedient!

I don't think there is a native API for getting the natural device orientation in any OS. Regardless, iOS only allows you to lock device orientation properly with a build hint so that wouldn't be very useful.

Related

Delphi Android get device orientation

I want to detect the device orientation in an app that is fixed to portrait mode. If I ask the IFMXScreenService, I get soPortrait no matter how the device is oriented.
This is logical, as the screen orientation is constantly soPortrait. But is there a different service that gives me the information I am after?

control orientation by sensor on Samsung devices

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.

Is there a way to disable portrait-upside down orientation but enable regular portrait and landscape orientations?

I need to prevent the upside-down portrait orientation in my app, but still allow all three of the other orientations to be triggered by physically rotating the device.
I'm calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) (which I understand to be the default) in onCreate() of my activities. The reason I am calling this is because some of my screens need to be specifically set to portrait and/or landscape, but most screens by default use the sensor.
This seems to result in my desired behaviour on some devices (Nexus 6, Samsung Galaxy S4), but the Nexus 7 displays portrait upside down mode when the device is held upside down. For unrelated reasons I can't allow this.
Is there a way to disable portrait upside-down on all devices but still allow the other 3 modes?
Unspecified let's the implementation decide what it wants to do. On the Neus 7, this is apparantly to allow everything, like SCREEN_ORIENTATION_FULL_SENSOR.
You could circumvent this by specifying the slightly less "Do whatever you want" option, being SCREEN_ORIENTATION_SENSOR.

App still rotates in landscape mode when device's Screen Orientation setting is off

I set my app to rotate 180 degrees by setting android:screenOrientation="sensorLandscape" on the activities in my manifest. But when the setting for screen orientation in device is turned off, the app is still rotating.
My app needs to rotate 180 degress in landscape mode but should not rotate when screen orientation setting is turned off. How can I solve this?
I believe you should be using landscape and not sensorLandscape. The sensor type attributes don't respect the orientation lock, and will still rotate regardless of that setting.
I couldn't seem to find out for sure whether landscape meant both 90 and 270 degree landscape, but give it a shot -- I believe that's your answer.
I Haven't used this personally but from the doc here I can see
Note: When you declare one of the landscape or portrait values, it is
considered a hard requirement for the orientation in which the
activity runs. As such, the value you declare enables filtering by
services such as Google Play so your application is available only to
devices that support the orientation required by your activities. For
example, if you declare either "landscape", "reverseLandscape", or
"sensorLandscape", then your application will be available only to
devices that support landscape orientation. However, you should also
explicitly declare that your application requires either portrait or
landscape orientation with the element. For example,
. This
is purely a filtering behavior provided by Google Play (and other
services that support it) and the platform itself does not control
whether your app can be installed when a device supports only certain
orientations.
so you can try
<uses-feature android:name="android.hardware.screen.landscape"/>.

Android Compass Reading Different Values On Different Phones?

Hello :) I am working on an application that uses the compass and location to draw an arrow at the direction of a location. My problem is when I run my code on the emulator, all the arrows point the correct directions, and when I change the orientation of the emulator to landscape, all the arrows are still correct. But when I run the same application on my Nexus One, the arrows are all correct when the phone is vertical, but when it turns to landscape all of the arrow are off by 90 degrees. It keeps the "top" of the phone as the reference to North. Thus you must correct the compass for the orientation of the phone. Does this happen on all real phones and the emulator is the different one? Or is this just the Nexus One? Thanks :)
From my understanding the current way the compass works it is supposed to always use the "top" of the phone or "default orientation" for the correct reading. This could have been different on earlier versions of android. It is said it is then up to developers to compensate for the screen orientation to represent the true north with orientation changes. Same goes for the accelerometer the axis stay based off of default screen orientation (so for most phones portrait, but tablets most would be landscape).
I hate to refer you to the sdk but this link first paragraph explains:
http://developer.android.com/reference/android/hardware/SensorEvent.html

Categories

Resources