Skip to content

Instantly share code, notes, and snippets.

@ansisec
Created November 14, 2023 10:58
Show Gist options
  • Save ansisec/47f1761bc661e7e373049c76e3035a67 to your computer and use it in GitHub Desktop.
Save ansisec/47f1761bc661e7e373049c76e3035a67 to your computer and use it in GitHub Desktop.
P07 files
class Utils {
companion object {
fun getTempFilename(context: Context) : String =
File.createTempFile(
"image", ".img",
context.externalCacheDir
).absolutePath
fun createFileFromUri(
context: Context,
uri : Uri,
filename : String = getTempFilename(context)
) : String {
FileOutputStream(filename).use { outputStream ->
context.contentResolver.openInputStream(uri)?.use { inputStream ->
inputStream.copyTo(outputStream)
}
}
return filename
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment