我想创建一些隐藏文件夹,就像照片隐藏应用程序一样,并将所选图像从相册或相机隐藏到所选的隐藏文件夹中。我搜索了很多,但是找不到任何解决方案。请帮我找到一个解决方案。 提前致谢。
我想创建一些隐藏文件夹,就像照片隐藏应用程序一样,并将所选图像从相册或相机隐藏到所选的隐藏文件夹中。我搜索了很多,但是找不到任何解决方案。请帮我找到一个解决方案。 提前致谢。
To create hidden folders or files follow Hamid S. instructions:
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/.Image/");
file.mkdirs();
To prevent the eg. gallery app from showing pictures within /.Image/, create the additional (empty) file .nomedia
这可以防止媒体扫描器读取您的媒体文件,并通过MediaStore内容提供程序将它们提供给其他应用程序。但是,如果文件真正是私有的,则应将它们保存在应用专用目录中。
要创建隐藏的文件夹或文件,请使用名称中带有点 (.)
的文件夹或文件名。
假设您想创建一个名为Image
的文件夹并将其隐藏,则可以按以下方式创建...
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/.Image/");
file.mkdirs();
尝试这段代码:
String iconsStoragePath = Environment.getExternalStorageDirectory() + "/.NewFolder";
File sdIconStorageDir = new File(iconsStoragePath);
if(!sdIconStorageDir.isDirectory()){
sdIconStorageDir.mkdirs();//create storage directories, if they don't exist
}
public static void hideFile(File file)
{
File dstFile = new File(file.getParent(), "." + file.getName());
file.renameTo(dstFile);
}