我正在尝试生成文件名以使用ARCore和Kotlin保存AR模型。
private fun generateFileName() : String {
val date = SimpleDateFormat("yyyyMMddHHmmss", java.util.Locale.getDefault()).format(Date())
return Environment.getExternalStorageDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "CreCard/" + date + "_furniture_model.jpg"
}
我不知道该使用什么?
任何人都可以提供相同的解决方案摘要吗?
private File getAbsoluteFile(String relativePath, Context context) {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
return new File(context.getExternalFilesDir(null), relativePath);
} else {
return new File(context.getFilesDir(), relativePath);
}
}
此方法将返回文件的完整路径。
可以尝试此代码段
File cameraDir =new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM), "Camera");
If(cameraDir.exists()){
// return the path..
}else{
//Create dir with mkdirs method
}
还添加读/写外部存储的权限