Skip to content

Instantly share code, notes, and snippets.

@Ifeo-A
Last active August 27, 2020 16:56
Show Gist options
  • Save Ifeo-A/52cd602e7040a2fa15776bbeacf9ec04 to your computer and use it in GitHub Desktop.
Save Ifeo-A/52cd602e7040a2fa15776bbeacf9ec04 to your computer and use it in GitHub Desktop.
Creates a .jpg filename
private fun createImageFile(albumName: String): File?
{
val randomString = UUID.randomUUID().toString()
val fileLocation = File(
context?.getExternalFilesDir(Environment.DIRECTORY_PICTURES), albumName
)
fileLocation.apply {
if(!this.exists())
{
if(!this.mkdirs())
{
Log.d(
this.javaClass.simpleName, "Could not create $albumName in " +
"${context?.getExternalFilesDir(Environment.DIRECTORY_PICTURES)}"
)
return null
}
}
}
val timeStamp = SimpleDateFormat(
"EE-dd-MMM-yyyy-KK-mm:a",
Locale.getDefault()
).format(Date())
return File("${fileLocation.path}${File.separator}taken_on_${timeStamp}_$randomString.jpg")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment