首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android在私有模式下将照片保存在磁盘上

Android在私有模式下将照片保存在磁盘上
EN

Stack Overflow用户
提问于 2016-06-07 12:24:38
回答 2查看 2.3K关注 0票数 0

我可以使用以下方法将映像保存在磁盘中:

代码语言:javascript
复制
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);
        }

但是保存下来的所有图像都可以在手机的展厅中看到。我如何向用户隐藏它们?我的应用程序有私人文件夹吗?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-07 12:39:17

代码语言:javascript
复制
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

票数 0
EN

Stack Overflow用户

发布于 2016-06-07 12:40:20

使用Context.getFilesDir()而不是Environment.getExternalStorageDirectory()将其保存到内部存储。

从医生那里:

默认情况下,保存在这里的文件只能由应用程序访问。

看看此链接

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37679334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档