Java Sample
Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage); shareIntent.setType("image/jpeg"); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to))); //or remove createChooser to show a dialog with remember button
My Own Kotlin Sample
private fun imageButtonShare_OnClick(v: View) { val uri = Uri.fromFile(File(path)) val intent = Intent(Intent.ACTION_SEND) intent.putExtra(Intent.EXTRA_STREAM, uri) intent.setType(getMimeType(path)) startActivity(Intent.createChooser(intent,"Share")) } fun getMimeType(url: String): String? { var type: String? = null val extension = MimeTypeMap.getFileExtensionFromUrl(url) if (extension != null) { type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) } return type }
References
https://developer.android.com/training/sharing/send.html