getExternalStorageDirectory() 和 getDataDirectory() 之间的区别

Difference between getExternalStorageDirectory() and getDataDirectory()

我正在尝试获取 Android 设备的内部和外部存储路径。

这就是我在大多数设备中获取内部存储路径的方式

Environment.getExternalStorageDirectory().getPath()

上述方法适用于大多数设备,但有些设备此方法存在问题,即 return 正在访问 SD 卡路径。

有人可以告诉我如何在 Environment.getExternalStorageDirectory().getPath() return 外部存储路径(SD 卡路径)的设备中准确获取内部存储路径。

我也知道 Environment.getDataDirectory().getPath() 但此方法 return 值类似于 /dataEnvironment.getExternalStorageDirectory().getPath() 用于同一设备 returns /storage/sdcard0 当 SD 卡不存在时指向内部存储,但当存在 SD 卡时它给出指向 SD 卡而不是内部存储的路径。

谁能帮我理解以上两者之间的区别,并帮助我获取 Android 设备的内部存储路径?另外,请帮我找到一个适用于所有设备的解决方案。

编辑:任何认为post不合适的人请发表评论并告诉我原因,以便我以后牢记这一点。

I am referring to the Storage where generally files are saved such as WhatsApp Folder, DCIM, Download etc.

这就是 Android SDK 所指的 external storage

The above method is working in most of the device but some device this method is giving issue that is it is returning the SD Card path.

它应该 return 100% Android 设备上的外部存储位置。外部存储是否可移动取决于设备制造商。 大量 大多数Android 设备具有永久不可移动的外部存储,通常与设备的板载闪存中的internal storage 位于同一分区。

Someone who could tell me how to exactly get the Internal storage path in those device whose Environment.getExternalStorageDirectory().getPath() return External Storage path (SD Card path).

很可能没有这样的路径。

the Environment.getExternalStorageDirectory().getPath() for the same device returns /storage/sdcard0 which points to Internal Storage when SD Card is not present but when an SD Card is present it gives the path which points to SD Card and not Internal Storage.

getExternalStorageDirectory() 的值不应根据某些可移动媒体的存在与否而变化。如果您的描述是准确的,那么这是一个有缺陷的设备,您对此无能为力。当然,没有获得 "other" getExternalStorageDirectory() 值的标准方法,因为该值不应该改变。

(顺便说一句,你有什么设备是这样的?)

Can anyone help me understand the difference between the above two

getDataDirectory() 或多或少 return 是 internal storage 的根。我说 "more or less" 是因为应用程序从未真正使用此目录,而是使用特定于应用程序的子目录(例如 Context 上的 getFilesDir())。