【发布时间】:2020-11-09 01:12:20
【问题描述】:
打开失败:ENOENT(没有这样的文件或目录)
已添加清单,因为 Environment.getExternalStorageDirectory() 在 Android R 上已弃用。如果我将其更改为 getExternalFilesDir(),则路径将指向应用目录,而不是存储
android:requestLegacyExternalStorage="true"
Android Q 下面运行正常,但 Android R 出现 ENOENT 错误
protected Uri getImageFile()
{
String imagePathStr = IMAGE_FOLDER;
File path = new File(imagePathStr);
if (!path.exists()) {
path.mkdirs();
}
String finalPhotoName = "IMG" +
(withTimeStamp ? "_" + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date(System.currentTimeMillis())) : "")
+ ".png";
// long currentTimeMillis = System.currentTimeMillis();
// String photoName = imageName + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date(currentTimeMillis)) + ".jpg";
File photo = new File(path, finalPhotoName);
return Uri.fromFile(photo);
}
【问题讨论】: