/**
* 选择相机
*/
private void showCameraAction()
{
// 跳转到系统照相机
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getActivity().getPackageManager()) != null) {
// 设置系统相机拍照后的输出路径
// 创建临时文件
try {
mTmpFile = FileUtils.createTmpFile(getActivity());
} catch (IOException e) {
e.printStackTrace();
}
if (mTmpFile != null && mTmpFile.exists()) {
if (currentapiVersion < 24) {
// 从文件中创建uri
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTmpFile));
} else {
//兼容android7.0 使用共享文件的形式
ContentValues contentValues = new ContentValues(1);
contentValues.put(MediaStore.Images.Media.DATA, mTmpFile.getAbsolutePath());
Uri uri = getActivity().getApplication().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
}
startActivityForResult(cameraIntent, REQUEST_CAMERA);
} else {
Toast.makeText(getActivity(), "图片错误", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getActivity(), R.string.msg_no_camera, Toast.LENGTH_SHORT).show();
}
}