//解决7.0系统打开sd卡找不到文件的问题
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
}
将上边代码加入到打开相机的的方法中
private void openCamra() {
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
String fileName = "head_icon.jpg";//照片命名
String path = Constants.sdcardRoot + Constants.uploadPicPath;
File out = new File(path, fileName);
Uri uri = Uri.fromFile(out);
//解决7.0系统打开sd卡找不到文件的问题
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
}
// Uri uri = null;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// //通过FileProvider创建一个content类型的Uri
uri = FileProvider.getUriForFile(myContext, "lab.tonglu.com.hybriddemo", out);
// uri = FileProvider.getUriForFile(myContext, "com.lab.web.activity", out);
// } else {
// uri = Uri.fromFile(out);
// }
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加这一句表示对目标应用临时授权该Uri所代表的文件
// }
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
((Activity)myContext).startActivityForResult(intent, Constants.REQUST_CHOOSE_PIC_CAMERA);
}