来自相机的 onActivityResult 给出了空意图

onActivityResult from camera gives null intent

所以直到昨天,当我将 phone 升级到 5.0.0 并在 5.0.0 模拟器中测试应用程序时,它一直运行良好。基本上目的是让用户拍照,return,打开它允许裁剪,然后 return 并将其设置为图像视图。

之前一切正常,但现在 onActivityResult 中的 intent 为空。

代码如下:

public void takeDisplayPicture(View view) {

    final String TAKE_DISPLAY_PICTURE = "Take Display Picture";

    Log.d(TAKE_DISPLAY_PICTURE, "Clicked");

    try {

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, CAMERA_CAPTURE);

    } catch (ActivityNotFoundException e) {

        String msg = "Your device doesn't support a camera!";

        Toast toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
        toast.show();

    }

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    final String RETURN_DISPLAY_PICTURE = "Return Display Picture";

    Log.d(RETURN_DISPLAY_PICTURE, "Returned");

    if (resultCode == RESULT_OK && requestCode == CAMERA_CAPTURE) {

        picUri = data.getData();
        performCrop(picUri);

    } else if (requestCode == PIC_CROP) {

        Bundle extras = data.getExtras();
        bitmap = extras.getParcelable("data");
        displayPicture.setImageBitmap(bitmap);

    }

}

private void performCrop(Uri picUri) {

    try {

        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        cropIntent.setDataAndType(picUri, "image/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        cropIntent.putExtra("return-data", true);
        startActivityForResult(cropIntent, PIC_CROP);

    } catch (ActivityNotFoundException e) {

        String msg = "Your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
        toast.show();

    }

}

第一,Android does not have a CROP Intent.

关于nullUri,应该是null。引用 the ACTION_IMAGE_CAPTURE documentation:

The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field.

您没有 EXTRA_OUTPUT,因此您应该通过记录不完整的 (Bitmap)data.getExtras().get("data");.

获取图像