简体   繁体   中英

Android how to name image to save in /camera?

I built a camera app. My problem is that I want to continue the logical naming the default camera app uses.

EG: The camera app produces files such as:

IMG_20130104_033852
IMG_20130104_033853

If these are the only contents of my /camera folder, I should theoretically name my photo IMG_20130104_033854 . Should I look for the image with the "biggest" name and add a number or is there a better solution for this problem?

I would suggest building the name up until the point you get to the last sequence of numbers, and then you could look for the biggest number and add one to it if you feel like it.

So for instance, based off of today's date, you could build the IMG_20130121_ part. You could do File [] fList = f.listFiles(); , where f is pointing to the /camera/ directory. From there, you could check the files by doing fileName.startsWith("IMG_20130121_") in an IF statement.
From there, do a substring to grab the string-numbers after the last underscore (_), convert to Integer, and loop through until you finish comparing all the Integers.

I did this for folder names. A standalone cd burning device creates folders that start with ezb_ , followed by a number. I can paste my looping code tomorrow if this info wasn't enough.

As a sidenote, if you were to start your own naming algorithm after IMG_20130121_ , like adding an s or something, you'd still have to either keep track or look for the biggest number. You might as well just implement something like what I tried to explain. Let me know if I need to clarify!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM