https://www.jianshu.com/p/13f4b8f70947
里面的调用相机的方法需要改成下面的:
/**
* 可以是任意字符串,与mainfest里面保持一致
*/
private static final String AUTHORITY = "com.xxx.fileprovider";
private void takeCamera() {
//创建一个file,用来存储拍照后的照片
File outputFile = new File(Environment.getExternalStorageDirectory(), "upload.png");
try {
if (outputFile.exists()) {
outputFile.delete();//删除
}
outputFile.createNewFile();
} catch (Exception e) {
e.printStackTrace();
}
cameraFielPath = outputFile.getPath();
Uri imageUri;
if (Build.VERSION.SDK_INT >= 24) {
imageUri = FileProvider.getUriForFile(mContext,
AUTHORITY,
outputFile);
} else {
imageUri = Uri.fromFile(outputFile);
}
//启动相机程序
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, FILE_CAMERA_RESULT_CODE);
}
网友评论