I'm trying to share a video recorded from my app to a story in Instagram. I am not using this API: https://developers.facebook.com/docs/instagram/sharing-to-stories/
I'm using this method that works perfectly when sharing images, and to share videos it only works by sharing the feed, but not by sharing a story. In other words, 3 of the 4 functions I try to use work.
private void shareFileToInstagram(Uri uri, boolean isVideo) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
Intent feedIntent = new Intent(Intent.ACTION_SEND);
feedIntent.setType(isVideo ? "video/*" : "image/*");
feedIntent.putExtra(Intent.EXTRA_STREAM, uri);
feedIntent.setPackage("com.instagram.android");
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("com.instagram.android");
this.grantUriPermission(
"com.instagram.android", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
Intent chooserIntent = Intent.createChooser(feedIntent, "Compartir");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {storiesIntent});
startActivity(chooserIntent);
}
When I go to the share option in a story, my app just doesn't do anything. In the log I could see this error but I couldn't fix it:
W/ChooserActivity: No activity found for Intent { act=com.instagram.share.ADD_TO_STORY dat=/storage/emulated/0/Video/201952172025.mp4 typ=mp4 flg=0x10000001 pkg=com.instagram.android }