Rename camera images from exif data using tasker I apologize if this is a duplicate, I can't find anything up-to-date that really helps answer my question. 

I know this is nitpicky, but it's been a long battle and I am losing it. 

For some time, I have been annoyed with the fact that you can't customize the android camera app's naming convention. My workaround, since the dawn of Dropbox camera upload, has been to use dropbox to upload and rename my photos (yyyy-mm-dd HH.nn.ss.jpg) and then use dropsync to overwrite the original file in my camera photo. 

The problem I'm facing at the moment is that the camera in the hangouts app does not follow the same rules as the default camera app for my phone (Sony Xperia z3) so I end up with duplicates in my gallery of any image I happened to capture using hangouts instead of the camera. I could use the camera to take a picture and then share it using hangouts, but I decided instead to play around with Tasker and try to automate consolidating my images. (Another gripe I have is that Dropbox won't let me exclude folders, so I'd like to get rid of Camera Upload altogether and not have every screenshot I've ever taken backed up forever). 

The directory for the default camera is [internal storage]/DCIM/100ANDRO and for hangouts it is [internal storage]/DCIM/Camera

I have a profile (below) triggered by the "file modified" event that will move the new file in the "Camera" folder into the "DCIM" folder. However, there is often a race condition, so Dropbox will upload the image before it is moved and again after. So my problem of duplicate images is not yet solved. 


(click for larger version)

I'd like to forgo the Dropbox/Dropsync combo and instead use Tasker to rename a file as it is added to either of the camera folders. I'd like to use the same naming convention that Dropbox uses, but I can't figure out how Tasker can access the EXIF data from the image to rename the photo to something like "2014-12-30 10.23.56.jpg". 

So, as a tl;dr: I am using Tasker to move images captured from different apps into a common folder. Can anyone help me add a step to rename the file I am moving based on the date and time the image was captured?
Use Tasker's native Java calls

Java code

Use ExifInterface.getAttribute to solve this problem.

exif = new ExifInterface( %filename )
%datetime = exif.getAttribute(exif.TAG_DATETIME)


Implementation overview


Getting path of a .JPG from %filename Tasker variable
Construct a new ExifInterface class instance into exif Java variable
Get date &amp; time by exif.getAttribute Java function, and store results into %datetime Tasker variable
Free exif Java variable
Check %datetime is set (this is not set when .JPG is not contains EXIF info)




Step by step solution in Tasker


Add a new Code > Java Function action

a. Set ExifInterface to Class Or Object (or select by magnifying glass button)

b. Write new \\ {ExifInterface} (String) to Function (or select by magnifying glass button)

c. Write %filename to Param (String)

d. Write exif to Return {ExifInterface}


Add a new Code > Java Function action

a. Write exif to Class Or Object (or select by coffee button)

b. Write getAttribute \\ {String} (String) to Function (or select by magnifying glass button)

c. Write exif.TAG_DATETIME to Param (String)

d. Write %datetime to Return {String}


Add a new Code > Java Object action

a. Left Mode on Delete

b. and write exif to Name


Check %datetime is set - I added a conditional Flash for show %datetime


Done!