Android Lollipop issue - Cannot load image from camera to ImageView

谁说我不能喝 提交于 2019-12-05 02:45:08

问题


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?

The camera intent:

if (result.equals("CAMERA"))
{
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, RESULT_IMAGE_CAPTURE);
}

The actual action:

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);
    }
}   

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?


回答1:


OK, apparently this was the problem (and the solution) - Activity killed / onCreate called after taking picture via intent

I didn't have that line in my manifest (though i did define my activity as portrait): android:configChanges="orientation|keyboardHidden|screenSize"



来源:https://stackoverflow.com/questions/31425145/android-lollipop-issue-cannot-load-image-from-camera-to-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!