Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write file into DCIM directory exactly where camera does?

Suppose I am writing an alternative Camera application and wish to write images exactly into the same place as Camera does and name them exactly in the same name Camera does.

How would I accomplish this?

How to know the location of camera files?

How to know current naming convention?

How to gain permissions to that directory?

Any of answer would be appreciated.


Okay, suppose it is not really camera alternative. Suppose I would like to write formats other than images, like audio, video, or something else.

like image 320
Dims Avatar asked Jan 21 '17 17:01

Dims


3 Answers

How would I accomplish this?

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.separator + "You Dir. Name";

if you append any string to end this

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)

it will create dir inside the folder

How to know the location of camera files?

By default camera uses this location

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)

How to know current naming convention?

IMG_yyyyMMDD_timeStamp

How to gain permissions to that directory?

Using permission manager for Camera and External Storage permissions

like image 123
Hemanth S Avatar answered Oct 17 '22 00:10

Hemanth S


You cannot write exactly into the same folder as the default camera app does. But you can make use of Environment.getExternalStoragePublicDirectory(Environment.DI‌​‌RECTORY_DCIM)


mediaStorageDir = new File(Environment.getExternalStorageDirectory(), FOLDER_NAME);
Intent takePictureFromCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, 
     Uri.fromFile(mediaStorageDir));
startActivityForResult(takePictureFromCameraIntent, 100);

But, please note that this will create only a sub-folder in the DCIM directory and will not store exactly where the default camera does. But you can always create sub-folders with your required folder name.

like image 39
Sanal Varghese Avatar answered Oct 17 '22 00:10

Sanal Varghese


Things to keep in mind for this answer:

  • Every phone producer creates it's own Camera App, tailored to their hardware.

  • With the right permissions, App's can write (almost) everywhere they want...

Now to your question(s):

First, we don't know where the photo's are stored, and what the naming convention is. Every one and their mother has a different idea about what is best. So no "Hey it's always there".

Those who seek will find: get read & write permissions for the whole device. With that search the whole device to find in what folders the images are in. Now subtract the folders that come from "social media". My guess would be that the folder with the most and or latest images is the one that you want. To be sure, you will need testers, that trust you.

All that are found were not unorganized: just find the pattern used. There may be a standard for this. The big companies will surely have one. You can ask the device what maker it has. Note, that that answer might not be correct.

Ain't that a picture, no, it's a photo: And then you get the fun part of accessing the camera. Good times. Remember: request picture => get location of picture in memory => save picture as file. Best part, there is no enforcement of all parts of this API, so different devices need different instructions...

Have fun & Good luck!

ps, the downvotes are probably for the lack of code

like image 28
Flummox - don't be evil SE Avatar answered Oct 16 '22 22:10

Flummox - don't be evil SE