8

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!

Dilazak
  • 139
  • 1
  • 1
  • 11
  • That is what the Android SDK refers to as [external storage](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html). – CommonsWare Oct 06 '17 at 17:25

3 Answers3

13

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();
Community
  • 1
  • 1
Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
  • 2
    i want path of internal storage not external one – Dilazak Oct 06 '17 at 17:26
  • 2
    Believe me, it is the internal storage. – Nabin Bhandari Oct 06 '17 at 17:27
  • what if i have both internal storage and an sd card? – Dilazak Oct 06 '17 at 17:29
  • It will give you the internal shared storage directory. Just give it a shot! – Nabin Bhandari Oct 06 '17 at 17:30
  • ok its giving me /storage/emulated/0 thats one part and how can i get the storage of sd card then? – Dilazak Oct 06 '17 at 17:39
  • @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? – Jay Dangar Oct 29 '18 at 17:32
  • 1
    @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. – Nabin Bhandari Oct 30 '18 at 03:35
  • @NabinBhandari, Thanks for Clearing my doubts. Appretiate your answer and help. – Jay Dangar Oct 30 '18 at 05:50
  • 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. – basitj May 14 '20 at 19:48
  • this method is deprected whats next? – nirazverma Sep 17 '20 at 15:07
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

Romadro
  • 626
  • 4
  • 10
  • Actually i meant to say to the top of internal storage not root – Dilazak Oct 06 '17 at 17:30
  • @Dilazak 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 internal – Romadro Oct 06 '17 at 17:32
0

Try this,

String path = Environment.getExternalStorageDirectory().getAbsolutePath();
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81