【发布时间】:2022-01-06 22:03:06
【问题描述】:
Screenshot我正在开发应用程序,在该应用程序中我从相机拍照,并将该照片保存在 android 的根目录中,一切正常我面临的问题是它的名称,当文件保存时Concatenating extra Number 中的函数,
@SuppressLint("SimpleDateFormat") 私有文件 getImageFile() 抛出 IOException {
timeTicks = new SimpleDateFormat("ddMMMyyyy_hhmmss-").format(new Date());
imageName = "img-" + timeTicks; //30Nov2021_105137-
storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
imageFile = File.createTempFile(imageName, ".jpg", storageDir); //storage/emulated/0/Android/data/com.example.meterreadingrecord/files/Pictures/img-30Nov2021_105137-3304015006530902745.jpg
imageName = imageFile.getName();
currentImagePath = imageFile.getAbsolutePath();
return imageFile;
return imageFile;
}
3304015006530902745.jpg 这个额外的时间刻度与我正在创建的文件名连接,
任何人都可以帮助我吗?请
提前感谢
【问题讨论】:
-
如果你不想要file name format of
createTempFile,为什么还要使用createTempFile -
不要自己创建文件。只需创建一个 File 对象:
File imageFile = new File(getExternalFilesDir(Environment.DIRECTORY_PUCTURES), fileName); -
就是创建图片文件的函数
-
if (cameraIntent.resolveActivity(getPackageManager()) != null) { imageFile = null;尝试 { imageFile = getImageFile();
-
私有文件 getImageFile() 抛出 IOException { timeTicks = new SimpleDateFormat("ddMMMyyyy_hhmmss-").format(new Date()); imageName = "img-" + timeTicks; storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); imageFile = File.createTempFile(imageName, ".jpg", storageDir); imageName = imageFile.getName(); currentImagePath = imageFile.getAbsolutePath();返回图像文件; }
标签: android camera android-camera android-camera2 android-camera-intent