Android Lollipop Camera2 api change app orientation

I'm building an app and part of it is where a user can change their profile picture, either by taking a picture or using it in their own gallery.

So I am using the built in camera and I am using the following lines of code to open the camera view

  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image_saved_destination));
        startActivityForResult(intent, CAMERA_REQUEST_CODE);

      

Thus, it saves the overwrite of the same file to external storage.

This worked fine until I updated my os on one of my devices to lollipop. Now when I use the camera, if I hold it in a portrait, take a pic and keep the orientation, when it returns to my app, it jumps from landscape to portrait. However, when the camera is open and if I hold my phone in landscape mode and shoot the pic and press "Save", it returns to the app without orientation anomalies.

Due to the orientation change and the change back, I lose the activity state, so my variables, etc. are lost, which are needed to process the image data.

Has anyone come across this?

+3


source to share


2 answers


The ACTION_IMAGE_CAPTURE and rotation between activity changes are not associated with the new Android camera2. This is just the standard behavior of the Android intent system and switching between activities.

It looks like the new OS comes with a new version of its own camera app that has changed its behavior in terms of controlling screen orientation. You should learn the standard approaches with orientation control and other configuration changes: http://developer.android.com/guide/components/activities.html#ConfigurationChanges



The ones that will allow you to either change the orientation yourself, reload your activity, or allow you to hide your personal data in a package that is provided to you in onCreate.

+3


source


Better Build your own camera using the camera API. If you run into the same problem again, you can use setDisplayOrientation to preview the camera. For more information visit Android. Side camera preview



-1


source







All Articles