@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); filePath = getOutputMediaFile(FileColumns.MEDIA_TYPE_IMAGE); File file = new File(filePath); Uri output = Uri.fromFile(file); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(MediaStore.EXTRA_OUTPUT,output); startActivityForResult(i,RETURN_FILE_PATH); } @Override protected void onActivityResult(int requestCode,int resultCode,Intent data) { super.onActivityResult(requestCode,resultCode,data); //data is always null here. //requestCode = RETURN_FILE_PATH; //resultCode = Activity.RESULT_OK; }
我检查了文件和输出Uri的值,两者都很好,捕获的图像实际上存在于该位置.
但是,即使在捕获图像之后,onActivityResult中返回的数据也始终为null.
编辑:
我查了这个问题:
onActivityResult returns with data = null
其中说:
Whenever you save an image by passing EXTRAOUTPUT with camera intent
the data parameter inside the onActivityResult always return null. So,
instead of using data to retrieve the image,use the filepath to
retrieve the Bitmap.