I hope to get the default directory of photo made by camera in android.
I think that the Code A can do that, and /storage/sdcard0/DCIM
is displayed in log,
but in fact, my photos made by camera are stored in the folder /storage/extSdCard/DCIM
How can I get the default directory of photo made by camera in android? Thanks!
Code A
File dir10 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
Log.e("MainActivity", "getExternalStoragePublicDirectory() 10:" + dir10.toString());
More
It seems that the default storage location of photos made by camera is set by user, sometimes it's Memory card, somtimes it's SD card. I hope know which storage location the user selected for store photos made by camera.
Your photos will be in one of two areas: The Pictures folder or the DCIM folder.
Camera Roll is a photo gallery app that offers a fluid and elegant interface where you can comfortably view all your photos, GIFs, and videos. Plus, you can see all the Exif information for each of your photos.
(2) (Digital Camera IMages) A folder name in a digital camera, smartphone or tablet for storing images taken with the device. Sometimes a "photos" folder points to that location.
Use getExternalStoragePublicDirectory()
with parameter DIRECTORY_PICTURES
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(path, "DemoPicture.jpg");
DIRECTORY_DCIM is the traditional location for pictures and videos when mounting the device as a camera.
DIRECTORY_PICTURES is Standard directory in which to place pictures that are available to the user.
Hope it helps !
As per documentation, There are two options
DIRECTORY_DCIM The traditional location for pictures and videos when mounting the device as a camera.
File musicDirectory = new File( getExternalFilesDir(Environment.DIRECTORY_DCIM));
DIRECTORY_PICTURES Standard directory in which to place pictures that are available to the user.
File musicDirectory = new File( getExternalFilesDir(Environment.DIRECTORY_PICTURES));
getExternalFilesDir() will return File object
you can refer here developer page
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.
}
Environment.getExternalStoragePublicDirectory
is used to get directories on internal storage only.
To get the DCIM folder on your secondary storage (if exists) you need to follow this code:
String secondStorage = System.getenv("SECONDARY_STORAGE");
File file = new File(secStore + "/DCIM");
File[] listFiles = file.listFiles();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With