Questions tagged [android-external-storage]

Tag for questions related with saving data to/reading data from an Android device external storage.

Every Android-compatible device supports a shared "external storage" that you can use to save files. This can be a removable storage media (such as an SD card) or an internal (non-removable) storage. Files saved to the external storage are world-readable and can be modified by the user when they enable USB mass storage to transfer files on a computer.

Caution: External storage can become unavailable if the user mounts the external storage on a computer or removes the media, and there's no security enforced upon files you save to the external storage. All applications can read and write files placed on the external storage and the user can remove them.

Useful links

827 questions
97
votes
10 answers

READ_EXTERNAL_STORAGE permission for Android

I'm trying to access media files (music) on the users device to play them; an easy "hello world"-music player app. I've followed some tutorials and they basically give the same code. But it won't work; it keeps crashing and telling…
83
votes
7 answers

Universal way to write to external SD card on Android

In my application, I need to store lots of images in the device storage. Such files tend to fulfill the device storage, and I want to allow users to be able to choose external SD card as the destination folder. I read everywhere that Android…
Vektor88
  • 4,841
  • 11
  • 59
  • 111
48
votes
2 answers

How does storage access change on Android 6?

Background Android had a lot of changes as to how to handle the SD-card and storage in general: API 3 - you get all access, no permission needed API 4-15 - you need to use WRITE_EXTERNAL_STORAGE, and you get all access. API 16-18 - if you wish only…
47
votes
16 answers

Android: mkdirs()/mkdir() on external storage returns false

I'm driven crazy with this: Log.d("STATE", Environment.getExternalStorageState()); File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "work_data"); Log.d("PATH", f.getAbsolutePath()); if (!f.exists()) { …
MHM
  • 854
  • 1
  • 9
  • 17
42
votes
3 answers

Android 10: What are my options to save files on external storage into a directory called "/sdcard/my-app/"

Up until Android Pie I always stored files which the app needed to get stored on /sdcard/my-app/, which I got via File fBaseDir = new File(Environment.getExternalStorageDirectory(), "my-app"); One of my App stores hundreds (up to multiple thousands)…
Daniel F
  • 13,684
  • 11
  • 87
  • 116
37
votes
8 answers

Android Open External Storage directory(sdcard) for storing file

I want to open external storage directory path for saving file programatically.I tried but not getting sdcard path. How can i do this?is there any solution for this?? private File path = new…
yuva ツ
  • 3,707
  • 9
  • 50
  • 78
29
votes
5 answers

Saving files in Android 11 to external storage(SDK 30)

I am writing a new Application on Android 11 (SDK Version 30) and I simply cannot find an example on how to save a file to the external storage. I read their documentation and now know that they basicly ignore Manifest Permissions…
Robert
  • 325
  • 1
  • 3
  • 5
23
votes
2 answers

Accessing external storage in Android API 29

I'm trying to achieve some clean up tools. More and more manufacturers have forbidden rooting devices due to some "security reason", it's forbidden NOT to request for unlock. After API 28, This code will make…
23
votes
1 answer

Media scanner for secondary storage on Android Q

With the newer Android Q many things changed, especially with scoped storage and gradual deprecation of file:/// URIs. The problem is the lack of documentation on how to handle media files correctly on Android Q devices. I have a media file (audio)…
20
votes
1 answer

How app can access files on USB OTG storages in Android 6.0 (API level 23) without root?

Android 6.0 Developer Preview (API level 23) can natively mounts external removable USB OTG storages out-of-the-box without any additional apps (for more info please see:…
19
votes
4 answers

Android APIv29 FileNotFoundException EACCES (Permission denied)

I'm not able to access storage when building for targetSdkVersion v29. Here is my gradle configuration: compileSdkVersion 29 buildToolsVersion "29.0.2" ... minSdkVersion 15 targetSdkVersion 29 NOTE that…
19
votes
2 answers

Why don't I have permission to write to app dir on external storage?

The TL;DR question summary: My Android app tries to write to the app's external storage directory on an SD card. It fails with a permissions error. But the same code (method), extracted into a minimal test app, succeeds! Since our target API level…
LarsH
  • 27,481
  • 8
  • 94
  • 152
19
votes
2 answers

How to copy file using adb to android directory accessible from PC

If you attach android device to PC you can browse files and dirs. It is possible to get this directory using Environment.getExternalStorage(). You can use it from your application and create accessible files and dirs. It works fine. On my devices…
kemsky
  • 14,727
  • 3
  • 32
  • 51
19
votes
3 answers

SecurityException: Permission Denial: reading (only on emulator)

I have two activities in my app, MainActivity calls ImagePicker, which has a GridView laying out all the images in the phone gallery, where I use a ContentResolver to get the cursor. It worked fine on my phone when I tested it but crashed every time…
19
votes
3 answers

getExternalCacheDir() returns null after clearing data

I have a simple app that access and writes data to external storage. Everything works fine until I go to Settings -> Apps -> App Info and clear data via "Clear data" button, then every call to getExternalCacheDir() starts returning null. I have been…
Ondřej Z
  • 5,094
  • 3
  • 24
  • 30
1
2 3
55 56