How to get absolute path of Internal Storage in Android
Asked Answered
C

3

9

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!

Christiachristian answered 6/10, 2017 at 17:15 Comment(1)
That is what the Android SDK refers to as external storage.Marni
R
14

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();
Ramtil answered 6/10, 2017 at 17:22 Comment(10)
i want path of internal storage not external oneChristiachristian
Believe me, it is the internal storage.Ramtil
what if i have both internal storage and an sd card?Christiachristian
It will give you the internal shared storage directory. Just give it a shot!Ramtil
ok its giving me /storage/emulated/0 thats one part and how can i get the storage of sd card then?Christiachristian
@NabinBhandari, I got your point and it works, but why they chose External Storage as a name for internal storage path? I am still confuse with your answer. And also will it always gives me Internal Storage Path or there's a catch? I mean will it select External Storage path if available? and also what the way to access External Storage Directory?Predictory
@JayDangar In android programming terms, Internal storage means the storage private to the application and external storage means the storage outside of it. Generally the device storage is considered as the primary external storage. You cannot directly access the secondary external storage. For that you will need to use Storage Access Framework.Ramtil
@NabinBhandari, Thanks for Clearing my doubts. Appretiate your answer and help.Predictory
I think that's not the right answer. This gives the path to the external storage. Internal storage is the folder inside your app where you save local files.Excretion
this method is deprected whats next?Sechrist
K
1

Try this,

String path = Environment.getExternalStorageDirectory().getAbsolutePath();
Koral answered 3/8, 2020 at 14:1 Comment(0)
H
0

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

Hemielytron answered 6/10, 2017 at 17:21 Comment(2)
Actually i meant to say to the top of internal storage not rootChristiachristian
@Christiachristian external doesn't mean you will store it on sdcard. I recommend you do as Android docs recommends you. Store shared files on the external storage, and private files on the internalHemielytron

© 2022 - 2024 — McMap. All rights reserved.