Skip to content

Instantly share code, notes, and snippets.

@Tarelochkin
Created February 24, 2018 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tarelochkin/034de00af301e0eeca15a5b375b6b269 to your computer and use it in GitHub Desktop.
Save Tarelochkin/034de00af301e0eeca15a5b375b6b269 to your computer and use it in GitHub Desktop.
Create a file with a filename containg current date
static File createTempImageFile(Context context) throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = context.getExternalCacheDir();
return File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment