public void startCamera2(View view){
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Uri photoUri = Uri.fromFile(new File(mFilePath));//显示的路径有权限风险
photoUri = FileProvider.getUriForFile(
this,
getPackageName() + ".provider",
new File(mFilePath));
intent.putExtra(MediaStore.EXTRA_OUTPUT,photoUri); //更改照片存储路径到photoUri
startActivityForResult(intent,REQ_2); //打开相机拍照,返回相机结果(照片)并回到原界面
}
//onActivityResult部分代码
else if(requestCode == REQ_2){
FileInputStream fis = null;
try {
fis = new FileInputStream(new File(mFilePath));
Bitmap bitmap = BitmapFactory.decodeStream(fis); //涉及写入内存卡权限,在manifest里面配置
// Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(photoUri));
mImageView.setImageBitmap(bitmap); //从内存读取原图