Android的新图像捕获从相机使用文件提供程序和保存在根目录



屏幕截图我正在使用应用程序,在该应用程序中,我从相机中拍摄照片,并将照片保存在android的根目录中,一切都很好,我面临的问题是它的名称,当文件获得时,将功能保存在Concatenating extra Number中,

@SuppressLint("SimpleDateFormat"(private File 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这个额外的时间刻度与我正在创建的文件名相连

有人能帮我吗??请

提前感谢

如blackapps评论中所建议的,使用

File imageFile = new File(getExternalFilesDir(Environment.DIRECTORY_PUCTURES), fileName); 

而不是

imageFile = File.createTempFile(imageName, ".jpg", storageDir);

解决了问题。

最新更新