Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

enter image description here

like image 527
HelloCW Avatar asked Jun 16 '16 01:06

HelloCW


People also ask

What folder are camera pictures in Android?

Your photos will be in one of two areas: The Pictures folder or the DCIM folder.

What is camera roll folder in Android?

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.

What does DCIM mean on Android?

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


3 Answers

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 !

like image 127
Abhishek T. Avatar answered Nov 09 '22 04:11

Abhishek T.


1.This will work only if user didn't change the default Camera output Dir

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

2. There is another trick you can do if you have atleast taken one pic taken in camera

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. 
 }
like image 22
Jayanth Avatar answered Nov 09 '22 05:11

Jayanth


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();
like image 28
Muhammad Ashraf Avatar answered Nov 09 '22 05:11

Muhammad Ashraf