Last active
August 27, 2020 16:56
-
-
Save Ifeo-A/52cd602e7040a2fa15776bbeacf9ec04 to your computer and use it in GitHub Desktop.
Creates a .jpg filename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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