How to get the default photo catalog made by camera in android?

I hope to get the default photo catalog made by the camera in android.

I think code A can do this, but is /storage/sdcard0/DCIMdisplayed in the log,

but actually my photos taken by the camera are stored in a folder /storage/extSdCard/DCIM

How can I get the default photo catalog made by the camera in android? Thank!

Code A

File dir10 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
Log.e("MainActivity", "getExternalStoragePublicDirectory() 10:" + dir10.toString());

More details

It seems that the default location for storing photos taken by the camera is set by the user, sometimes it's a memory card, sometimes it's an SD card. I hope I know what storage location the user has selected for storing photos taken by the camera.

enter image description here

+4
source share
3

1. , Dir

DIRECTORY_DCIM .

File musicDirectory = new File( getExternalFilesDir(Environment.DIRECTORY_DCIM));

DIRECTORY_PICTURES , , .

File musicDirectory = new File( getExternalFilesDir(Environment.DIRECTORY_PICTURES));

getExternalFilesDir()

2. , ,

String[] projection = new String[]{MediaStore.Images.ImageColumns._ID,MediaStore.Images.ImageColumns.DATA,MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,MediaStore.Images.ImageColumns.DATE_TAKEN,MediaStore.Images.ImageColumns.MIME_TYPE};     
final Cursor cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,projection, null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"); 
if(cursor != null){
    cursor.moveToFirst();
    //you can access last taken pics here. 
 }
+3

Environment.getExternalStoragePublicDirectory .

DCIM ( ), :

String secondStorage = System.getenv("SECONDARY_STORAGE");
File file = new File(secStore + "/DCIM");
File[] listFiles = file.listFiles();
+2

Use with the DIRECTORY_PICTURES parameter getExternalStoragePublicDirectory()

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(path, "DemoPicture.jpg");

DIRECTORY_DCIM is a traditional place for images and videos when installing the device as a camera.

DIRECTORY_PICTURES is a standard directory where you can place images available to the user.

Hope this helps!

+2
source

All Articles