Skip to content

Instantly share code, notes, and snippets.

@stepango
Created May 6, 2017 09:31
Show Gist options
  • Save stepango/9d6150230852205f985304f6cf3843bf to your computer and use it in GitHub Desktop.
Save stepango/9d6150230852205f985304f6cf3843bf to your computer and use it in GitHub Desktop.
Share audio file using Android Intent
fun shareItem(item: RecordingItem) {
val requestFile = File(item.filePath)
// Use the FileProvider to get a content URI
val fileUri: Uri = FileProvider.getUriForFile(
context,
"${BuildConfig.APPLICATION_ID}.fileprovider",
requestFile
)
val share = Intent(Intent.ACTION_SEND)
share.type = "audio/*"
share.setDataAndType(fileUri, context.contentResolver.getType(fileUri))
share.putExtra(Intent.EXTRA_STREAM, fileUri)
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
context.startActivity(Intent.createChooser(share, "Share Sound File"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment