Intent Image Capture data==null

2019-07-15 04:52发布

问题:

I have this code, and it works perfectly in an Ericsson XPERIA, but when I test the app in a SAMSUNG ACE, appears the error :

data=null

String  file=Environment.getExternalStorageDirectory().getAbsolutePath()+ "/picture.jpg";

    Intent i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);  
    Uri output = Uri.fromFile(new File(archivo));           
    i.putExtra(MediaStore.EXTRA_OUTPUT, output);
    startActivityForResult(i,CAMERA_REQUEST);

OnActivity Result

if (requestCode==CAMERA_REQUEST && resultCode==RESULT_OK){
                    Bundle extras=data.getExtras();
                    bmp=(Bitmap)extras.get("data");
                    image.setImageBitmap(bmp);
                    image.setVisibility(0);

Any idea why this is happening?

回答1:

When you use EXTRA_OUTPUT and specify a file you usually don't get any image data via the result intent as an extra. The camera app is instead supposed to write the data to the file you specified.

If you include that extra you should read the output from your file instead once you receive RESULT_OK. Or you can remove EXTRA_OUTPUT to make data in the result intent reliable on all devices. Note that this returns a low-resolution picture since the intent system is not build to deliver huge amounts of data.