?
public static String getTime(byte[] jpegData) { if (jpegData == null) return null; ExifInterface exif = getExif(jpegData); return exif.getTagStringValue(ExifInterface.TAG_DATE_TIME); }?
String dateTime = Exif.getTime(mData); if (null != dateTime) { mDateTaken = stringToLong(dateTime); }注意要加保护,因为在某些模式下的多张合成照片不是每张都能在exif中取得值;并且注意在
mTitle = createName(mFileType, mDateTaken, mGroupIndex);?这句之前赋值。
?
private long stringToLong (String dateTime) { Log.d(TAG, "Brandon, the date time string is "+ dateTime); // eg. cut the string from 2015:12:24 10:01:52\C0\80 to 2015:12:24 10:01:52 dateTime = dateTime.substring(0, 19); SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); Log.d(TAG, "Brandon, the cutted string is " + dateTime); try { Date date = format.parse(dateTime); return date.getTime(); } catch(ParseException e) { Log.e(TAG, "[stringToLong] ParseException: " + e); return 0; } }
?其中那个时间格式是从android相片的exif中取得的,要用substring截取第0个index到第19(不包括19)个。
注意Date的parse方法必须放在try...catch对里。
需要
import java.text.SimpleDateFormat; import java.text.ParseException;
?
?
原文:http://phoobobo.iteye.com/blog/2266324