Skip to content

Instantly share code, notes, and snippets.

@rafaelalveriano
Forked from michaeltys/ShareFileToInstagram
Created February 16, 2021 13:11
Show Gist options
  • Select an option

  • Save rafaelalveriano/9999007aec44afc32944269a4d0b0842 to your computer and use it in GitHub Desktop.

Select an option

Save rafaelalveriano/9999007aec44afc32944269a4d0b0842 to your computer and use it in GitHub Desktop.
Sharing an image to instagram stories or create a post
private void shareFileToInstagram(Uri uri, boolean isVideo, Post post) {
Intent feedIntent = new Intent(Intent.ACTION_SEND);
feedIntent.setType(isVideo ? "video/*" : "image/*");
feedIntent.putExtra(Intent.EXTRA_STREAM, uri);
feedIntent.setPackage(Constants.INSTAGRAM_PACKAGE_NAME);
Intent storiesIntent = new Intent("com.instagram.share.ADD_TO_STORY");
storiesIntent.setDataAndType(uri, isVideo ? "mp4" : "jpg");
storiesIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
storiesIntent.setPackage(Constants.INSTAGRAM_PACKAGE_NAME);
activity.grantUriPermission(
"com.instagram.android", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
Intent chooserIntent = Intent.createChooser(feedIntent, getString(R.string.social_instagram));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {storiesIntent});
startActivity(chooserIntent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment