I currently have a method for sharing an image in Instagram stories that works for me, it opens the Instagram app directly with the activity to post a storie:
private fun shareWithInstagramStories(contentUri: Uri): Intent {
val intent = Intent("com.instagram.share.ADD_TO_STORY")
val sourceApplication = context?.getString(R.string.facebook_app_id)
intent.putExtra("source_application", sourceApplication)
intent.setDataAndType(contentUri, "image/jpeg")
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
return intent
}
I want to do something similar but for Instagram Direct, is there anything similar? I know the Spotify app has a custom share dialog that opens up this direct message activity, but I don't know how they do it. Right now this is it:
private fun shareWithInstagramDirect(contentUri: Uri): Intent {
return Intent(Intent.ACTION_SEND).apply {
type = "image/jpeg"
putExtra(Intent.EXTRA_STREAM, contentUri)
`package` = "com.instagramm.android"
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
}
What it does is launch an Instagram dialogue that gives me a choice between Reels, Stories, Direct and Feed, but I would like to launch the direct directly.