**
Android7.0 系统以前
**
File file = new File(currentCameraPath);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, ImageUtils.REQUEST_CODE_GETIMAGE_BYCAMERA);
**
Android7.0 系统以后
**
//LocalAlbum为获取本地相册的类
Uri imageUri;
String authority = LocalAlbum.this.getPackageName() + ".provider";
File cameraFile = new File(currentCameraPath);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
//通过FileProvider创建一个content类型的Uri
imageUri = FileProvider.getUriForFile(LocalAlbum.this, authority, cameraFile);
} else {
imageUri = Uri.fromFile(cameraFile);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, ImageUtils.REQUEST_CODE_GETIMAGE_BYCAMERA);
总结:Android7.0以上获取系统相机方法主要是把 “Uri.fromFile(file)”换成“FileProvider.getUriForFile(当前类, authority, cameraFile)”