Intent Image Capture data==null

99封情书 提交于 2020-01-04 11:03:23

问题


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.



来源:https://stackoverflow.com/questions/12286514/intent-image-capture-data-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!