简体   繁体   English

Android Lollipop Camera2 api改变app的方向

[英]Android Lollipop Camera2 api changing orientation of app

I am creating an application and part of it is where the user can change their profile picture either by taking a picture or using one from the native gallery. 我正在创建一个应用程序,其中一部分是用户可以通过拍照或使用本机库中的一个来更改其个人资料图片。

So I'm using the native camera and I'm 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);

So with this it keeps overwriting the same file on the external storage. 因此,它会一直覆盖外部存储上的相同文件。

This was working fine until I updated my os on one of my devices to lollipop. 这工作正常,直到我将我的一个设备上的操作系统更新为棒棒糖。 Now when I use the camera if I keep it in held in portrait and take the pic and save the orientation when it returns to my app flips from landscape to portrait. 现在,当我使用相机时,如果我将它保持在肖像中并拍摄照片并保存方向,当它返回到我的应用程序翻转从横向到纵向。 However, when the camera is open and if I hold the phone in landscape and take the pic and click save, it returns to the app with no orientation abnormalities. 但是,当相机打开时,如果我将手机保持在横向状态并拍摄照片并单击保存,它将返回到没有方向异常的应用程序。

Due to the orientation being changed and changed back I lose the state of the activity so my variables etc are lost, which are needed for processing the image data. 由于方向被改变和改变,我失去了活动的状态,因此我的变量等丢失,这是处理图像数据所需要的。

Has anyone encountered this? 有没有遇到过这个?

The ACTION_IMAGE_CAPTURE intent and the rotation between activity changes, are not related to the new Android camera2 API at all. ACTION_IMAGE_CAPTURE意图和活动更改之间的轮换根本与新的Android camera2 API无关。 This is just standard behavior of Android's intent system and switching between activities. 这只是Android意图系统的标准行为以及活动之间的切换。

It sounds like the new OS comes with a new version of the native camera app, which has changed its behavior in terms of managing screen orientation. 听起来新的操作系统附带了一个新版本的原生相机应用程序,它改变了它在管理屏幕方向方面的行为。 You should look into the standard approaches with managing orientation and other configuration changes: http://developer.android.com/guide/components/activities.html#ConfigurationChanges 您应该查看管理方向和其他配置更改的标准方法: http//developer.android.com/guide/components/activities.html#ConfigurationChanges

Those will allow you to either handle the orientation change yourself instead of the OS restarting your activity, or allow you to stash your private data into a bundle that is given to you in onCreate. 这些将允许您自己处理方向更改而不是重新启动活动的操作系统,或者允许您将私有数据存储到onCreate中提供给您的包中。

更好你使用相机API创建自己的自定义相机。如果你再次遇到相同的问题,你可以使用相机预览的 setDisplayOrientation。更多访问Android - 相机预览侧身

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM