How can I find out the camera images folder of an Android phone?
Asked Answered
I

3

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...)

Informant answered 7/6, 2013 at 21:24 Comment(0)
V
22

Use getExternalStoragePublicDirectory()

with parameter DIRECTORY_PICTURES

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

Viscera answered 7/6, 2013 at 21:30 Comment(8)
Ah! So DIRECTORY_PICTURES doesn't return the top level gallery directory? That's what was confusing me.Informant
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.Frog
@Frog Thanks very much! This really is what I was searching for.Decorator
@Frog 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 "." ?Shout
@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.Frog
I see. How come the thumbnails folder doesn't have the ".nomedia" file, so that it won't be scanned by the MediaStore ? are images that are stored in folders that start with "." being ignored ?Shout
Looks like the answer only find out one directory right? is there anyway to list all Folder Picture better than Just run the for loop inside SD card to check where is DIRECTORY_PICTURE?Mellissamellitz
How can I get the default directory of photo made by camera in android?Owain
B
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.

Bromo answered 25/1, 2015 at 16:21 Comment(1)
This approach doesn't seem right to me. For example, my DCIM directory has 4 folders inside.Wardlaw
S
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
    ...
Scandic answered 21/4, 2016 at 3:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.