Questions tagged [android-storage]

Android uses a file system that's similar to disk-based file systems on other platforms. There's a specific way how to perform read and write on files within Android file system using the File APIs.

Android uses a file system that's similar to disk-based file systems on other platforms. There's a specific way how to perform read and write on files within Android file system using the File APIs.

All Android devices have two file storage areas: "internal" and "external" storage. These names come from the early days of Android, when most devices offered built-in non-volatile memory (internal storage), plus a removable storage medium such as a micro SD card (external storage). Many devices now divide the permanent storage space into separate "internal" and "external" partitions. So even without a removable storage medium, these two storage spaces always exist, and the API behavior is the same regardless of whether the external storage is removable.

Because the external storage might be removable, there are some differences between these two options as follows.

Internal storage:

  • It's always available.
  • Files saved here are accessible by only your app.
  • When the user uninstalls your app, the system removes all your app's files from internal storage.

Internal storage is best when you want to be sure that neither the user nor other apps can access your files.

External storage:

  • It's not always available, because the user can mount the external storage as USB storage and in some cases remove it from the device.
  • It's world-readable, so files saved here may be read outside of your control.
  • When the user uninstalls your app, the system removes your app's files from here only if you save them in the directory from getExternalFilesDir().

External storage is the best place for files that don't require access restrictions and for files that you want to share with other apps or allow the user to access with a computer.

And all of the mentioned two variants of data/file storage within Android involves various other techniques related to Permissions within the Android System which the developers has to write code in order to handle it smoothly without interrupting the end user actions.

Other than the above two areas it involves few other ways of Data Storage within Android systems such as shared-preferences and databases, but that's not relevant to our tag Android-storage.

Some parts of this description was excerpts from following article from Android developer documents: https://developer.android.com/training/data-storage/files

338 questions
411
votes
36 answers

Exception 'open failed: EACCES (Permission denied)' on Android

I am getting open failed: EACCES (Permission denied) on the line OutputStream myOutput = new FileOutputStream(outFileName); I checked the root, and I tried android.permission.WRITE_EXTERNAL_STORAGE. How can I fix this problem? try { …
Mert
  • 6,432
  • 6
  • 32
  • 68
115
votes
15 answers

Android 11 Scoped storage permissions

My App use the file paths of images provided by Environment.getExternalStorageDirectory() to create albums of photos, but with Android 11 I won't be able to access directly files. According to the Android developers documentation they recently…
Rob B
  • 1,249
  • 2
  • 7
  • 13
104
votes
6 answers

how to access downloads folder in android?

I am new android, i'm making an app in which one can download files to downloads folder (using Download Manager). I can see pictures if i go to downloads folder in emulator. So if i want to show a slideshow of downloaded files how can i get the…
Dhruv
  • 1,668
  • 9
  • 29
  • 40
27
votes
5 answers

Delete folder from internal storage in android?

How to delete folder(contain some folder and file) from internal storage? Folder have some below tree. folder |_________ C2 (folder) |________1 (folder) |________1.gif |________2.gif …
duggu
  • 37,851
  • 12
  • 116
  • 113
10
votes
4 answers

How can I delete file on Android 11 (API 30) without system confirmation dialog?

I have an app which records videos to shared MOVIES folder. I can delete those files on Android 11 (API 30) with contentResolver.delete(uri, null, null) method in my recorded videos activity. But if I reinstall the app then it looses permissions to…
user25
  • 2,873
  • 2
  • 30
  • 66
9
votes
1 answer

Is it possible to programmatically access Download folder on Android Q (SDK >= 29)?

I want to list all files .txt in the Download folder and then allow the user to pick one and read its content. My minSdkVersion is 16, but I came across this problem because my Android is Q (29). What I tried: Apparently…
Rafael Tavares
  • 5,678
  • 4
  • 32
  • 48
9
votes
3 answers

How to set a file as a ringtone for Android 10?

I used to use following code to save a raw sound file to external storage and set it as ringtone. But things seems to change in android 10. Can you help me or show me some guideline how to update my code to work with android 10? Here is the code to…
Figen Güngör
  • 12,169
  • 14
  • 66
  • 108
8
votes
1 answer

PDF.js can't show PDF from externalFilesDir at Android 11

I am using PDF.js to show PDF files inside my Android App. Up to Android 10 it worked fine, but starting with "targetSdkVersion 30" it doesn't work anymore. If I want to open and show a PDF file, PDF.js shows Missing PDF…
Tefracky
  • 171
  • 1
  • 7
8
votes
4 answers

How to create folder (Android R - Api 30)?

Read that Android 11 has scoped storage, but I can't find any information, how can I create and use folder in /storage/emulated/0/ ? Old methods works only on api 29 and below :(
Fedor Sedov
  • 101
  • 1
  • 1
  • 8
8
votes
3 answers

Accessing public download files onActivityResult Android 28 Samsung Galaxy S9+ (Verizon)

UPDATE I have a Samsung Galaxy S8+ running 8.0.0 T-Mobile that it works fine on running 8.0.0 My Samsung Galaxy S9+ running 8.0.0 Verizon, it fails everytime with illegal argument. My Samsung Galaxy S9+ running 8.0.0 T-Mobile has no…
Sam
  • 5,342
  • 1
  • 23
  • 39
7
votes
2 answers

How to use Espresso's intenting with DocumentsProvider results

My activity needs to request a new document from a document provider. I want to test this in my espresso test by intenting an activity result with a uri. However, the returned uri does not have the correct permissions granted. At least I get a…
friedger
  • 645
  • 7
  • 21
6
votes
1 answer

How to save a file (image) in Android and support API levels from 21 to 29?

All new apps uploaded to Google Play must target Android 10 (API level 29) or higher. However, when app targets API level 29, the path returned from Environment.getExternalStorageDirectory() is no longer directly accessible to apps. Documentation…
Viktor Brešan
  • 5,293
  • 5
  • 33
  • 36
6
votes
1 answer

Is there a straightforward way to get the parent directory's Uri from a file Uri?

Suppose a Uri can be either of the following: A Uri from a Storage Access Framework's DocumentFile (i.e. DocumentFile.getUri()). A Uri from a regular File (i.e. Uri.fromFile(File)) It refers to a file under a directory in both situations. Is there…
Hong
  • 17,643
  • 21
  • 81
  • 142
6
votes
2 answers

ACTION_GET_CONTENT Intent not showing external storage

I'm implementing an import feature for my Android app. I wanted to let the user select files which they want to import from the external storage on their device (the downloads directory to be exact) and other online file storages such as DropBox and…
5
votes
1 answer

Android: Folder Picker ONLY

I have an application where when I press on a button it should open the folder picker and allow the user to browse and select a folder ONLY. Then I want to get the folder's path so that I can do some manipulation with it. I've tried using this…
Mervin Hemaraju
  • 1,921
  • 2
  • 22
  • 71
1
2 3
22 23