How to get absolute path of Internal Storage in An

2019-06-23 16:03发布

Internal Storage Path

Consider the above picture. It shows the folders and file in internal storage. My problem is i am not able to get the absolute path of the internal storage. I Have tried using

String path = getFilesDir().getAbsolutePath();

but it is giving me the path of my app storage. My objective is to backup a file from the private storage of my app to the top of internal storage. And i am unable to find a solution on web and neither on stack overflow. Suggest a solution to this problem!

3条回答
够拽才男人
2楼-- · 2019-06-23 16:31

I'm using the following path to access the top of internal storage:

/storage/emulated/0/my_file.txt

For this you don't need any root permission.

查看更多
不美不萌又怎样
3楼-- · 2019-06-23 16:43

It is only possible with root access. You should write you backup to external storage to make it world-readable. Android docs says that if you want to share file with other apps or store this file even after app will be deleted you should save it to external storage. Android docs

查看更多
贼婆χ
4楼-- · 2019-06-23 16:55

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();
查看更多
登录 后发表回答