Skip to content

Instantly share code, notes, and snippets.

@HasibPrince
Created September 24, 2023 20:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HasibPrince/fa503633e63bde8a4facd390f4964a33 to your computer and use it in GitHub Desktop.
Save HasibPrince/fa503633e63bde8a4facd390f4964a33 to your computer and use it in GitHub Desktop.
Usage of MediaStore API
val contentResolver = this.contentResolver
val contentValues = ContentValues().apply {
put(MediaStore.MediaColumns.DISPLAY_NAME, "applounge")
put(MediaStore.MediaColumns.MIME_TYPE, "text/plain")
put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS)
}
val uri = contentResolver.insert(MediaStore.Files.getContentUri("external"), contentValues)
uri?.let {
contentResolver.openOutputStream(it)?.use { outputStream ->
outputStream.write(fullMessage.toByteArray())
outputStream.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment