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.

tasker profile to move newly created image
(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?

  • If the trigger is "file modified", can you not use the current date/time instead of trying to read the image's EXIF? – Chahk Dec 30 '14 at 19:11
  • I could, but I don't know how to do that either. As far as I can tell I can't specify the format for the %DATE variable either (I'm a Tasker noob though, so I'm sure it can be done). And when I look in my file explorer, under the picture filename it shows the date and time, I don't know how fast Tasker operates so I'm not sure if it would have the exact same time (down to the seconds). – Penelope Clearwater Dec 30 '14 at 19:14
  • You may want to look into getFormattedDate function. In terms of timing, File Modified should be instantaneous. You will only run into issues if you have more than one file in the monitored folder, but then some kind of a counter (appended to the end of the new filename) in your loop may help. – Chahk Dec 30 '14 at 19:29
  • Oh wow, that works. I had tried that earlier but I was using it completely wrong. Thanks! – Penelope Clearwater Dec 30 '14 at 19:43
  • I'll post that as the answer then. – Chahk Dec 30 '14 at 19:45

Since you are using the "file modified" trigger (which should be instant at the moment the file is written,) you can use the current date and time instead of trying to extract the EXIF data from the images.

Tasker's getFormattedDate function will help with parsing the date/time and constructing the new file name. The only issue you might have is if the source folder contains more than one image. You can use a counter variable within your loop and append it to the end of the file name to mitigate that.


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

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

Step by step solution in Tasker

  1. 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}

  2. 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}

  3. Add a new Code > Java Object action

    a. Left Mode on Delete

    b. and write exif to Name

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.