我想从相机拍摄图片并将其发送到另一个称为segmentImage2()的函数,该函数获取捕获图像的Uri 问题是:相机拍摄图像,但是发送到该功能的图像的Uri为空
这是我的代码
private void setCapture(){
btn_fab=(FloatingActionButton)findViewById(R.id.fab);
btn_fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String root =Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString()+"propic.jpg";
uri=Uri.parse(root);
startActivityForResult(i,REQUEST_IMAGE_CAPTURE);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Logger.debug("requestCode = %d, resultCode = %d, data = %s",
requestCode,
resultCode,
data);
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Uri ImageCaptureUri=data.getData();
Logger.debug("capture: %s", ImageCaptureUri);
if (ImageCaptureUri != null) {
if (Build.VERSION.SDK_INT >= 19) {
final int takeFlags = data.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION;
getContentResolver()
.takePersistableUriPermission(ImageCaptureUri, takeFlags);
}
segmentImage2(ImageCaptureUri);
}
}
private void segmentImage2(Uri ImageCaptureUri){
Fragment fragment = findFragment(R.id.fragment_segment_bitmaps);
if (fragment instanceof SegmentBitmapsFragment) {
((SegmentBitmapsFragment)fragment).segmentBitmap2(ImageCaptureUri);//important note
}
}