0

我正在编写一个应用程序,其中我将照片保存在内部存储中。我正在使用此博客中的解决方案

我以前知道两个文件的名称,所以我可以有一个代码,但在我的应用程序中也会有一个画廊。所以我的问题是:如何在不知道文件名的情况下保存文件(文件名是使用日期和时间生成的)?内容提供者的 oncreate 在初始化期间开始,那么如何将新文件名传递给内容提供者?

提前致谢。

4

1 回答 1

1

在内容提供者类中删除 onCreate 文件创建完全。

public static String lastPictureSaved = "";

改变功能openFile。在那里,文件名将根据日期时间和创建的文件来制作。

 Date date = new Date();     
 date.getTime();
 SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_HHmmss");
 String datetimestr = formatter.format(date);       
 lastPictureSaved = getContext().getFilesDir() + "/" + datetimestr + ".jpg";        
 File f = new File(lastPictureSaved);

 try
   {
    f.createNewFile();
   }
 catch (IOException e)
   {
    e.printStackTrace();

    Log.d(TAG, e.getMessage());
   }

在主机活动更改

 File out = new File(getFilesDir(), "newImage.jpg");

 File out = new File(MyFileContentProvider.lastPictureSaved);
于 2014-07-07T17:06:24.147 回答