Android Lollipop issue - Cannot load image from camera to ImageView(Android Lollipop 问题 - 无法将图像从相机加载到 ImageView)
问题描述
在 android lollipop 之前的任何版本上,以下代码都可以正常工作.出于某种原因,从某个版本的android(大约5.0)开始,每当从相机捕获图像时,屏幕都会向右和向后旋转90度(不仅我的设备上的自动旋转关闭,我的活动被定义为肖像,它根本不应该旋转!).一旦屏幕旋转回来,ImageView 就会显示上一个(原始)图像.有什么建议吗?
On any version before android lollipop, the below code works fine. For some reason, from a certain version of android (around 5.0), whenever an image is captured from camera, the screen rotates 90 degrees to the right and back (Not only auto-rotate on my device is off, my activity is defined as portrait, it's not supposed to be rotating at all!). Once the screen rotates back, the ImageView presents the previous (original) image. Any suggestions?
相机意图:
if (result.equals("CAMERA"))
{
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, RESULT_IMAGE_CAPTURE);
}
实际操作:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Bitmap bmp = null;
if (requestCode == RESULT_IMAGE_CAPTURE && resultCode == RESULT_OK && data != null)
Bitmap bmp = (Bitmap) data.getExtras().get("data");
if (bmp != null)
{
mProfilePicPath = ImageHandler.saveBitmap(bmp , "", "image_name");
mProfilePic.setImageBitmap(bmp);
}
}
编辑:显然,当从相机意图返回我的活动时,不仅仅是要调用的 onResume() 方法,而是调用 onCreate() 方法,而且不仅仅是一次,而是两次!第一次没有问题,因为它之后调用了onActivityResult方法.但是,第二次重新启动 mProfilePic(我的 ImageView)和 mProfilePicPath,我想稍后使用它们.有什么想法吗?
EDIT: Apparently when going back to my activity from the camera intent, rather than just the onResume() method to be called, the onCreate() method is called, and not just once, but twice! The first time is not a problem, since the onActivityResult method called after it. The second time, though, re-initiates both mProfilePic (my ImageView) and mProfilePicPath, which I want to use later. Any ideas?
推荐答案
好的,显然这就是问题(和解决方案) -通过意图拍照后调用的活动终止/onCreate
OK, apparently this was the problem (and the solution) - Activity killed / onCreate called after taking picture via intent
我的清单中没有该行(尽管我确实将我的活动定义为肖像):android:configChanges="orientation|keyboardHidden|screenSize"
I didn't have that line in my manifest (though i did define my activity as portrait): android:configChanges="orientation|keyboardHidden|screenSize"
这篇关于Android Lollipop 问题 - 无法将图像从相机加载到 ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android Lollipop 问题 - 无法将图像从相机加载到 ImageView
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01