我可以使用以下方法将映像保存在磁盘中:
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = imageId + ".png";
String filePath = baseDir + File.separator + fileName;
File file = new File(filePath);
if(!file.exists())
{
out = new FileOutputStream(baseDir + File.separator + fileName);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
}但是保存下来的所有图像都可以在手机的展厅中看到。我如何向用户隐藏它们?我的应用程序有私人文件夹吗?
谢谢
发布于 2016-06-07 12:39:17
public File getAlbumStorageDir(Context context, String albumName) {
// Get the directory for the app's private pictures directory.
File file = new File(context.getExternalFilesDir(
Environment.DIRECTORY_PICTURES), albumName);
if (!file.mkdirs()) {
Log.e(LOG_TAG, "Directory not created");
}
return file;
}我想这就是你想要的。有关更多信息,请阅读https://developer.android.com/training/basics/data-storage/files.html#WriteExternalStorage。
发布于 2016-06-07 12:40:20
使用Context.getFilesDir()而不是Environment.getExternalStorageDirectory()将其保存到内部存储。
从医生那里:
默认情况下,保存在这里的文件只能由应用程序访问。
看看此链接。
https://stackoverflow.com/questions/37679334
复制相似问题