gpt4 book ai didi

java - 来自相机的 onActivityResult 给出了 null Intent

转载 作者:行者123 更新时间:2023-12-01 11:47:39 25 4
gpt4 key购买 nike

所以直到昨天我将手机升级到 5.0.0 并在 5.0.0 模拟器中测试该应用程序时,它都工作得很好。基本上目的是允许用户拍照,返回它,打开它以允许裁剪,然后返回它并将其设置为 ImageView 。

之前一切正常,但现在 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 .

对于null Uri,它应该是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");< 获取图像.

关于java - 来自相机的 onActivityResult 给出了 null Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29031053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com