Hanbit the Developer
[Kotlin] Get URI from byte array in android 본문
fun getUriFromByteArray(byteArray: ByteArray): Uri{
// Set directory
val dir = File(requireContext().getExternalFilesDir(null).toString() + "/YOUR_DIR")
if(! dir.exists()){
dir.mkdir()
}
// Create dummy file
val file = if(url.endsWith(".mp4")){
File.createTempFile("post_media", ".mp4", dir)
}else{
File.createTempFile("post_media", ".webm", dir)
}
// Write bytes to the file
val os = FileOutputStream(file)
os.write(byteArray)
os.close()
return Uri.fromFile(file)
}
'Android' 카테고리의 다른 글
[Kotlin] RecyclerView in SwipeRefreshLayout in NestedScrollView Implementation (0) | 2021.09.24 |
---|---|
[Kotlin] Delete whole directory in android (0) | 2021.08.19 |
[Kotlin] How to make 'instagram comment layout' using Span. (0) | 2021.08.10 |
[Kotlin] Set indent to first line of TextView in android (0) | 2021.08.10 |
[Kotlin] TextView의 더보기 기능 구현 (0) | 2021.08.08 |