[英]onActivityResult from camera gives null intent
so this was working lovely till yesterday when I upgraded my phone to 5.0.0 and tested the application out in a 5.0.0 emulator. 所以直到昨天我将手机升级到5.0.0并在5.0.0模拟器中测试该应用程序时,它的工作情况都很不错。 Basically the purpose is to allow the user to take a photo, return it, open it to allow cropping then return it and set it as an imageview.
基本上,目的是允许用户拍摄照片,返回照片,打开照片以进行裁剪,然后返回并将其设置为imageview。
Everything worked fine before but now the intent in onActivityResult is null. 之前一切正常,但现在onActivityResult中的意图为null。
Here's code: 这是代码:
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();
}
}
First, Android does not have a CROP
Intent
. 首先, Android没有
CROP
Intent
。
With respect to the null
Uri
, it is supposed to be null
. 关于
null
Uri
,它应该为null
。 Quoting the ACTION_IMAGE_CAPTURE
documentation : 引用
ACTION_IMAGE_CAPTURE
文档 :
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written.
调用方可以传递一个额外的EXTRA_OUTPUT来控制该图像的写入位置。 If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field.
如果不存在EXTRA_OUTPUT,则会在Extra字段中将一个小型图像作为Bitmap对象返回。
You do not have EXTRA_OUTPUT
, and so you are supposed to get your image via the poorly-documented (Bitmap)data.getExtras().get("data");
您没有
EXTRA_OUTPUT
,因此应该通过记录较差的(Bitmap)data.getExtras().get("data");
获取图像(Bitmap)data.getExtras().get("data");
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.