android - "getDataDir()"与 getFilesDir 有何不同?

标签 android

返回文件对象的“getDataDir()”已从 API 24 添加。如果使用它,它要求最低 API 级别为 24。

文档将其用法解释为:

Returns the absolute path to the directory on the filesystem where all private files belonging to this app are stored. Apps should not use this path directly; they should instead use getFilesDir(), getCacheDir(), getDir(String, int), or other storage APIs on this class.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

No additional permissions are required for the calling app to read or write files under the returned path.

getDataDir()(在 API 24 中添加)与 getFilesDir() 或 Environment.getDataDirectory() 有何不同?

该功能可以在哪些可能的场景下使用?.我知道现有的路径函数 <=23

最佳答案

getFilesDir() 返回的目录将在 getDataDir() 中。两者都与返回所有内部存储的根的 Environment.getDataDirectory() 没有任何关系。

In what possible scenarios can the function be used?

一种情况是对该应用的内部存储上的所有文件实现某种应用内完整备份。

关于android - "getDataDir()"与 getFilesDir 有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39920986/

相关文章:

php - 为什么我无法在 Android 设备上接收来自 GCM 的消息

java - 绘制多个自定义 View

android - 针对不同设备缩放 Android Canvas 2D 图形

android - 是否可以通过 make 或 Soong 构建使用 Kotlin 的 Android 应用程序?

android - 如何在 Android DatePicker 中设置最小和最大日期?

php - 将字符串数组发送到 php

android - Firebase:无法初始化崩溃报告

php - 执行 php 请求时如何传递多参数字符串

未检测到标题栏中的android向上按钮按下

java - 读取 csv 但发生 java.io.FileNotFoundException : (No such file or directory)