【问题标题】:Android camera intent losing reference of Imageview in LollipopAndroid 相机意图失去对 Lollipop 中 Imageview 的引用
【发布时间】:2016-02-02 12:46:43
【问题描述】:

我有一个活动,我在点击时调用相机的意图,但是当我捕获图像并返回活动结果时,我的图像视图引用为空。我得到了正确的 URI。这发生在 android Lollipop 中。

Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
               startActivityForResult(captureIntent, 1);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {

        if (requestCode == 1) {
            Bundle extras = data.getExtras();

            Bitmap thePic = extras.getParcelable("data");
            //retrieve a reference to the ImageView
            Log.i("dataa",String.valueOf(thePic));
            Log.i("dataaimg",String.valueOf(image));
            Log.i("dataaimgno",String.valueOf(imageno));
            image.setImageBitmap(thePic); // here is the problem image reference is null when get back here
        }

    }  

此代码在棒棒糖以下版本中运行良好。

【问题讨论】:

  • 你在哪里设置image的值?
  • 我正在将捕获的图像设置为 Imageview

标签: android android-intent imageview android-camera android-camera-intent


【解决方案1】:

试试这个:

private static final int CAPTURE_IMAGE_ACTIVITY_REQ = 0;

Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAPTURE_IMAGE_ACTIVITY_REQ );


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQ) {
        if (resultCode == RESULT_OK) {

        Bitmap bp = (Bitmap) data.getExtras().get("data");
        image = setImageBitmap(bp);
}
}

【讨论】:

  • 感谢您的回复,我得到的图片参考为空
  • 你做过ImageView image = (ImageView) findViewById(R.id.yourImage) ??
  • 是的,这个问题只发生在棒棒糖版本上。它在棒棒糖下面工作正常
猜你喜欢
  • 1970-01-01
  • 2015-10-04
  • 1970-01-01
  • 1970-01-01
  • 2023-04-11
  • 2011-02-13
  • 1970-01-01
相关资源
最近更新 更多