如何在 Android 中获取内部存储的绝对路径

How to get absolute path of Internal Storage in Android

Internal Storage Path

考虑上图。它显示内部存储中的文件夹和文件。我的问题是我无法获得内部存储的绝对路径。我试过使用

String path = getFilesDir().getAbsolutePath();

但它为我提供了我的应用程序存储路径。我的 objective 是从我的应用程序的私有存储备份一个文件到内部存储的顶部。而且我无法在网络上找到解决方案,也无法在堆栈溢出上找到解决方案。提出这个问题的解决方案!

只有root权限才有可能。您应该将备份写入外部存储,以使其全球可读。 Android 文档说,如果您想与其他应用程序共享文件或存储此文件,即使在应用程序将被删除后,您也应该将其保存到外部存储。 Android docs

Environment.getExternalStorageDirectory();

Return the primary shared/external storage directory.

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

File dir = Environment.getExternalStorageDirectory();
String path = dir.getAbsolutePath();

试试这个,

String path = Environment.getExternalStorageDirectory().getAbsolutePath();