Questions tagged [android-sdcard]

SD Card is a Secure Digital Card available with Android which acts as the External Storage Directory.

Android supports also access to an external storage system e.g. the SD card. All files and directories on the external storage system are readable for all applications.

You can get the path to the external storage system via the Environment.getExternalStorageDirectory() method. To write to the external storage system your application needs the android.permission.WRITE_EXTERNAL_STORAGE permission.
Note: Beginning with Android 4.4, that permission is not required if you're reading or writing only files that are private to your app. For more information, see the section below about saving files that are app-private.

Before you do any work with the external storage, you should always call getExternalStorageState() to check whether the media is available. The media might be mounted to a computer, missing, read-only, or in some other state.

To check for the write permisson you should check the result of the

Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)

And for the read permisson

Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) ||
Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY)

Useful links

1499 questions
629
votes
30 answers

Solution to INSTALL_FAILED_INSUFFICIENT_STORAGE error on Android

The INSTALL_FAILED_INSUFFICIENT_STORAGE error is the bane of every Android developer's life. It happens regardless of app size, or how much storage is available. Rebooting the target device fixes the problem briefly, but it soon comes back. There…
Andrew Smith
  • 2,589
  • 3
  • 19
  • 17
131
votes
14 answers

How to delete a file from SD card

I am creating a file to send as an attachment to an email. Now I want to delete the image after sending the email. Is there a way to delete the file? I have tried myFile.delete(); but it didn't delete the file. I'm using this code for Android, so…
mudit
  • 25,306
  • 32
  • 90
  • 132
127
votes
7 answers

How do I adb pull ALL files of a folder present in SD Card

I have a folder in my SD Card as: /mnt/sdcard/Folder1/Folder2/Folder3/*.jpg The name of Folder1 and Folder2 remains constant and inside Folder2 I have Folder3, 4, 5 and so on.. I want to pull all the jpeg files rather than all files (there are more)…
riteshtch
  • 8,629
  • 4
  • 25
  • 38
125
votes
3 answers

How to use the new SD card access API presented for Android 5.0 (Lollipop)?

Background On Android 4.4 (KitKat), Google has made access to the SD card quite restricted. As of Android Lollipop (5.0), developers can use a new API that asks the user to confirm to allow access to specific folders, as written on the this…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
116
votes
14 answers

Android get free size of internal/external memory

I want to get the size of free memory on internal/external storage of my device programmatically. I'm using this piece of code : StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); long bytesAvailable =…
Android-Droid
  • 14,365
  • 41
  • 114
  • 185
110
votes
4 answers

Reading an image file into bitmap from sdcard, why am I getting a NullPointerException?

How can I read an image file into bitmap from sdcard? _path = Environment.getExternalStorageDirectory().getAbsolutePath(); System.out.println("pathhhhhhhhhhhhhhhhhhhh1111111112222222 " + _path); _path= _path + "/" + "flower2.jpg"; …
Smitha
  • 6,110
  • 24
  • 90
  • 161
95
votes
26 answers

How can I get the external SD card path for Android 4.0+?

Samsung Galaxy S3 has an external SD card slot, which is mounted to /mnt/extSdCard. How can I get this path by something like Environment.getExternalStorageDirectory()? This will return mnt/sdcard, and I can't find the API for the external SD card.…
Romulus Urakagi Ts'ai
  • 3,699
  • 10
  • 42
  • 68
88
votes
11 answers

Android: How to open a specific folder via Intent and show its content in a file browser?

I thought this would be easy but as it turns out unfortunately it's not. What I have: I have a folder called "myFolder" on my external storage (not sd card because it's a Nexus 4, but that should not be the problem). The folder contains some *.csv…
kaolick
  • 4,817
  • 5
  • 42
  • 53
86
votes
4 answers

How do you write to a folder on an SD card in Android?

I am using the following code to download a file from my server then write it to the root directory of the SD card, it all works fine: package com.downloader; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import…
RailsSon
  • 19,897
  • 31
  • 82
  • 105
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
69
votes
6 answers

How can I read a text file from the SD card in Android?

I am new to Android development. I need to read a text file from the SD card and display that text file. Is there any way to view a text file directly in Android or else how can I read and display the contents of a text file?
RSSS
  • 809
  • 2
  • 8
  • 5
66
votes
13 answers

How to get file name from file path in android

I want to get file name from sdcard file path. e.g. :/storage/sdcard0/DCIM/Camera/1414240995236.jpg I want get 1414240995236.jpg I have written the code to fetch the same but it is not working. Please help. Below is my code: @Override protected…
Manikandan K
  • 1,081
  • 1
  • 9
  • 17
65
votes
7 answers

error opening trace file: No such file or directory (2)

I am getting the above error: error opening trace file: No such file or directory (2) when I run my android application on the emulator. Can someone tell me what could be the possible reason for this? I am using android-sdk-20 and below lines…
Ankit Jain
  • 2,230
  • 1
  • 18
  • 25
64
votes
6 answers

Check if directory exist on android's sdcard

How do I check if a directory exist on the sdcard in android?
Alxandr
  • 12,345
  • 10
  • 59
  • 95
52
votes
5 answers

Android 6.0 Marshmallow. Cannot write to SD Card

I have an app that uses external storage to store photographs. As required, in its manifest, the following permissions are requested
RudyF
  • 805
  • 1
  • 10
  • 16
1
2 3
99 100