Android Difficult Screen Orientation - android

I have recently started studying Android, and I would, as first application, create my own camera. After taking a look at the API and other examples on the internet, I was able to create a working app, however I have this problem: if I rotate the tablet that I'm using to try what I do, my app rotates in the wrong way.
So, when I switch from portrait to landscape, the transition is successful and buttons rotate correctly, but what camera really sees is as if it were rotated 90 degrees more than it should.
All this unless I decide to set in my activity screenOrientation: landscape, because in this case the camera sees everything correctly, but the buttons remain fixed in one place, don't rotate with the rotation of the tablet.
I have a tablet with only front-facing camera.
What can I do to fix the problem?

check this answer I gave some time ago, it does have a nice method to call to correctly set the camera orientation.
How can I know the position of the camera on an android device?
and with that code you should let your activity rotate freely

Related

Can you replicate Android Stock Camera rotation in flutter?

I've tried to replicate android's stock camera rotation in flutter but to no success. Either the whole app rotates, or nothing rotates. I tried to also dig deeper into the native code, but couldn't find anything that keeps the app static, while the whole system rotates behind the scenes. The main thing I am looking for is to keep the Camera view static (landscape mode), and rotate the UI with the system depending on the device orientation.

How to handle video orientation from mobile devices

I have a server component that processes video uploads for a web/iOS/Android application.
However I am running into a problem handling the video orientation. Is there a good way to solve this? I have a tool MediaInfo that rips the meta data out of the device but this is what i am encountering
iOS
the portrait is correct 90 or 270
the landscape is crazy. if you hold the device with the button to the left, it reports 0 for the front camera and 180 for the back
Android
here the situation is reversed the landscape is correct both front and back camera
the portrait is 90 or 270 depending on if you are using the front or back camera
furthermore some devices like Motorola Droids and Evo4G dont record the meta data at all
has anyone seen a clean solution for this?
There is no clean solution for android devices that do not report the orientation.
For all the other orientations, I had overly complicated it in my mind. The flip between front and back means the angles are correct if rotated clockwise

Android API - disable right landscape?

I am busy writing an app that lets me use my phone (Galaxy S2 2.2.3) as a steering wheel. Just a nerdy weekend project really.
I have gotten everything working regarding calculating the orientation of the device using SensorManager.GetOrientation() with a slight snag. The rotation around the axis which comes out of the screen and back of the phone rises from 0 to 90 degrees and then falls back down in the same manner to 0 degrees instead of proceeding to 180.
This had me really confused until I read something somewhere that suggested the API might be flipping (internally as the screen doesn't flip) orientation so the phones coordinates system is flipping from left to right landscape (Its worth noting that I have it locked in landscape mode in the Manifest). This explains the weird behaviour in terms of orientation.
Does anyone know how to stop this happening, or have I gone wrong completely in my understanding?

Do I have to use the accelerometer in Android to get my photos to orient correctly?

I notice that when you take photos with the native camera app, they come out portrait or landscape (as they should), however, when I take photos in my app using the Camera class, they are always landscape, no matter how I'm holding the device.
I'm really hoping I don't have to monitor the orientation of the device and manually rotate the images... is there a less silly way to get this done?
TIA
You dont need to use accelerometer. You can just check the orientation by the time the photo is taken.
Developer Android
getResources().getConfiguration().orientation

Zxing - Changing camera view -90 degrees

First of all, I would like to refer to this Issue on the google groups.
My problem is i want the landscape-native app to work in portrait mode. The way of getting the app into portrait mode is no problem at all, but when you display the app in portrait mode, my problem occurs.
When the Barcode Scanner is starting op, its camera view is (pr. default) at a +90 degree angle. When viewing the app in portrait mode the Barcode Scanner is (naturally) still at a +90 degree angle.
In the referred Issue-page there is displayed a hack to get around the problem, but this does not seem to work on most devices. This does also not work on my targeted devices.
I would like to hear if some of you have got a work around, or found the place in the source where you can 'undo' the 90 degree flipping?
A usable answer will be utmost appriciated :D Unfortunately i can't make progress in the project before this is solved. It is demanded to run in portrait mode ;)
In advance ... Thanks :)
I have implemented this in a private build. It is complicated and I can't share the details. The key steps are:
Call Camera.setDisplayOrientation() to counteract the rotation; see the Android javadoc for some discussion on that
Make sure that Camera.Parameters.setPreviewSize() is called correctly; preview sizes are reported in landscape but need to be set in portrait
(And guess what -- the default orientation of phones is considered portrait but tablets is considered landscape! Make sure you've accounted for that too.)
Finally, the preview data is always in landscape mode. You need to rotate it yourself to read it right-side-up, or otherwise account for that.

Categories

Resources