Android通过getRootDirectory等方法获取文件目录,然后写出文件,在本地找不到对应的文件,而且也无法读取以同样的方法获取到的文件路径,只有getExternalCacheDir能在本地找到对应文件,但还是不能读取,getFilesDir可以正常读取但在本地找不到文件
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
//动态申请权限
permission.requestPer(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, 1, new LllPermission.LllPermissionInter() {
@Override
public void execute() {
///storage/emulated/0/Android/data/io.github.grooters.lllerdemo/cache/lllerDemo_img.jpg
// imgFile=new File(getActivity().getExternalCacheDir(),PHOTO_FILE_NAME);
///storage/emulated/0/lllerDemo_img.jpg
// imgFile=new File(Environment.getExternalStorageDirectory(),PHOTO_FILE_NAME);
///data/user/0/io.github.grooters.lllerdemo/files/lllerDemo_img.jpg
imgFile=new File(getActivity().getFilesDir(),PHOTO_FILE_NAME);
///data/lllerDemo_img.jpg
// imgFile=new File(Environment.getDataDirectory(),PHOTO_FILE_NAME);
///system/lllerDemo_img.jpg
// imgFile=new File(Environment.getRootDirectory(),PHOTO_FILE_NAME);
Log.i(TAG,imgFile.getAbsolutePath());
try {
if(imgFile.exists()){
imgFile.delete();
}
imgFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
if(Build.VERSION.SDK_INT>=24){ //低于7.0用Uri.fromFile()将文件转换为Uri
photoUri= FileProvider.getUriForFile(getActivity(),"io.github.grooters.lllerdemo.fileprovider",imgFile);
}else{
photoUri=Uri.fromFile(imgFile);
}
}
});
错误类型
java.lang.IllegalArgumentException: Failed to find configured root that contains