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
21
votes
5 answers

External SDCard file path for Android

Is it true that the file path to external SDCard on Android devices are always "/storage/extSdCard"? If not, how many variations are there? I need it for my App to test the availability of external SDCard. I am using Titanium, it has a method…
Bowie
  • 992
  • 3
  • 10
  • 25
21
votes
7 answers

Check if the SDCard is present, boolean is always true

In my splash screen, I want to check if the phone has a SDCard. The Boolean statement is beneath: Boolean isSDPresent = android.os.Environment.getExternalStorageState() .equals(android.os.Environment.MEDIA_MOUNTED ); So, if I have…
Tobias Moe Thorstensen
  • 8,861
  • 16
  • 75
  • 143
20
votes
4 answers

Copy files from a folder of SD card into another folder of SD card

Is it possible to copy a folder present in sdcard to another folder present the same sdcard programmatically ?? If so, how to do that?
Siva Kumar
  • 893
  • 4
  • 14
  • 28
20
votes
8 answers

How to get the internal and external sdcard path in android

Most of the new android devices have an internal sdcard and an external sdcard. I want to make a file explorer app but I can't find out how to get the path to use in my app because File file = Environment.getExternalStorageDirectory(); just…
Mahmoud Jorban
  • 952
  • 4
  • 13
  • 25
19
votes
14 answers

mkdirs returns false for directory on sd card while the parent directory is writable

When starting my android application, I need to create a directory on the sd card, for a small number of users this fails and I can't figure out the reason for it... (I've found similar problems caused by the WRITE_EXTERNAL_STORAGE permission…
Danny
  • 473
  • 2
  • 5
  • 11
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
8 answers

ExoPlayer - play local mp4 file in SD card

I am using the Exoplayer Demo app and want to preload a MP4 video from SD card. I have tried out the implementation from this post, but it does not work. There is no such class called DemoUtil.java in my exoplayer Demo. Instead used: public static…
Meera Anand
  • 348
  • 1
  • 2
  • 8
19
votes
6 answers

Android 5.0 DocumentFile from tree URI

Alright, I've searched and searched and no one has my exact answer, or I missed it. I'm having my users select a directory by: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, READ_REQUEST_CODE); In my…
Joe Walton
  • 191
  • 1
  • 1
  • 4
19
votes
1 answer

How to create Android directory automatically if it doesn't already exist

I am creating a gallery app using a tutorial but get the following error: abc directory path is not valid! Please set the image directory name AppConstant.java class Please visit the following link to see the entire tutorial's code as I am using the…
user3739970
  • 591
  • 2
  • 13
  • 28
19
votes
2 answers

MediaStore.Images.Media.insertImage is returning null when trying to save the image

I am using an custom view and in that i am using an canvas in which a user can draw anything and after that i want to save that image in sd card bt was not able to do that. Don't know what is going on. else if(view.getId()==R.id.save_btn){ …
Pravesh
  • 822
  • 1
  • 8
  • 20
18
votes
8 answers

How to tell if the sdcard is mounted in Android?

I'm working on an Android application that needs to look at what images a user has stored. The problem is that if the user has the sdcard mounted via the USB cable, I can't read the list of images on the disk. Does anyone know of a way to tell if…
KFB
  • 516
  • 1
  • 5
  • 12
17
votes
5 answers

Android SD card writing, Permission Denied

I am trying to write a file to SDCard with below Code (permission android.permission.WRITE_EXTERNAL_STORAGE already set in manifest.xml). Upon execution of nmea_file.createNewFile(); it throws exception with Permission Denied. Any guesses why would…
user329604
  • 187
  • 1
  • 1
  • 4
17
votes
5 answers

how to hide images from android gallery

One part of my current project is downloading images from URL then saving to SDCard. But the problem is all of saved images in sdcard is displayed in android gallery page. What I want is "I don't want all of my saved images in android gallery."
PPShein
  • 13,309
  • 42
  • 142
  • 227
16
votes
4 answers

Get the list of paths of all the Storage Devices connected to an Android device

I want to get the list of all Storage Devices which are connected to the Android device. For eg- Internal Storage(Storage in which all the folders such as Downloads, DCIM etc are present), SD Card and OTG device. I Know there are a lot of…
Rahulrr2602
  • 701
  • 1
  • 13
  • 34
16
votes
6 answers

How to check availability of space on external storage?

How do you check if the SD card is full or not so that your application can decide if it can continue to do its job i.e. write to external storage or notify the user that storage has run out of space.
Namratha
  • 16,630
  • 27
  • 90
  • 125