问题描述
我在这样的外部存储中创建了一个文件
我的文件名是 (UP)VwJp5A9ASZFTmcIxVf+Yqg==.jpg
public static File createFileInExternalStorage(Context context,String filename,byte[] content) throws IOException{
// this is my external file dir path
// /storage/emulated/0/Android/data/{my package}/files
File file = new File(context.getExternalFilesDir(null),filename);
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(content);
fos.close();
return file;
}
然后我使用文件提供程序将其转换为 URI
File file = createFileInExternalStorage(context,filename,data);
String authority = context.getApplicationContext().getPackageName() + ".provider";
Uri processedUri = FileProvider.getUriForFile(context,authority,file);
但是我无法将此 URI 转回原始文件
String path = uri.getPath();
// path is -> /name2/(UP)VwJp5A9ASZFTmcIxVf+Yqg==.jpg
File fdelete = new File(path);
!fdelete.exists() // false
我的provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path name="name1" path="."/>
<external-files-path name="name2" path="." />
</paths>
uri.getPath()
中的 name2 肯定来自 external-files-path
中的 name
有人可以解释一下这个名字是什么吗?它在内部存储中创建一个名为 myimages 的文件夹?如果我只想将文件直接保存在内部存储文件夹(顶级)中怎么办?它强迫我创建一个子文件夹?
取自https://developer.android.com/training/secure-file-sharing/setup-sharing
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)