13

I am developing a camera app for Android.

One requirement is to save the photos taken to the device's default camera photo folder i.e. the folder in which Android's native camera stores it.

How can I figure out where the native camera is storing the photos it's taking - it is my understanding that this could be different for different makes (Samsung, HTC, Motorola, Sony...) and models (Galaxy Tab, Galaxy S4...)

3 Answers 3

22

Use getExternalStoragePublicDirectory()

with parameter DIRECTORY_PICTURES

(or, for other use cases, other similar parameters such as DIRECTORY_MOVIES)

8
  • Ah! So DIRECTORY_PICTURES doesn't return the top level gallery directory? That's what was confusing me.
    – OC2PS
    Jun 7, 2013 at 21:36
  • 18
    I would argue that DIRECTORY_DCIM is a better match: "The traditional location for pictures and videos when mounting the device as a camera". That being said, the "native camera" is welcome to do whatever it wants, and there is no way a priori for you to know where that camera stores its images. Jun 7, 2013 at 21:46
  • @CommonsWare Thanks very much! This really is what I was searching for. Oct 14, 2013 at 8:58
  • @CommonsWare but this folder usually also has a thumbnails folder. is it possible to get the folder of the camera itself? or maybe I should just ignore folders there that start with "." ? Feb 4, 2014 at 15:40
  • 1
    @androiddeveloper: "but this folder usually also has a thumbnails folder" -- I cannot speak to "usually", but DIRECTORY_DCIM can have subdirectories, created by the user or by apps. "is it possible to get the folder of the camera itself?" -- a camera does not have a folder. Camera apps can put images wherever they want, whether in DIRECTORY_DCIM directly, in a subdirectory off of DIRECTORY_DCIM, or somewhere else entirely. And, there are many, many camera apps. Feb 4, 2014 at 15:49
5

I know it's a little late for this, but you can do this:

String CameraFolder="Camera";
File CameraDirectory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString());
File[] files = CameraDirectory.listFiles();
for (File CurFile : files) {
      if (CurFile.isDirectory()) {
                CameraDirectory=CurFile.getName();
                break;
      }
}
final String CompleteCameraFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString() + "/" + CameraFolder;

Optionally, you can perform your operation inside the for loop.

1
  • This approach doesn't seem right to me. For example, my DCIM directory has 4 folders inside. Oct 8, 2015 at 2:14
2

Additional information on this topic. You need to add a permission to access the external storage or listFiles() always returns null. Add below to your AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.tomoima.filedirectory"
      xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application
    ...

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.