How can I share a video as a background and an image as a sticker together to Instagram Story?
This documentation has only one solution if both contents are images.
https://developers.facebook.com/docs/instagram/sharing-to-stories/
I would like to send a background video together with a sticker image. Is that possible with Instagram Story?
I tried that, but unfortunately it didn't work:
// Define image asset URI and attribution link URL
Uri backgroundAssetUri = Uri.fromFile(new File(backgroundPath));
Uri stickerAssetUri = Uri.fromFile(new File(stickerPath));
// Instantiate implicit intent with ADD_TO_STORY action,
// background asset, and attribution link
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
intent.setDataAndType(backgroundAssetUri, "*/*");
intent.putExtra("interactive_asset_uri", stickerAssetUri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
callbackManager.startActivityForResult(Intent.createChooser(intent, "Share"), NatShareCallbacks.ACTIVITY_SHARE_INSTAGRAM_STORY);
But the example with two images works without problems. I see the problem mainly with SetType, because they are two different content types.
[EDIT]
Video alone without stickers had already worked for me on Android and the example of the documentation with image-background and image-sticker also works perfectly. But not video and sticker together.
It works under iOS without any problems:
NSData *backgroundVideo = [[NSFileManager defaultManager] contentsAtPath:path];
UIImage *appIcon = [UIImage imageNamed: [[[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIcons"] objectForKey:@"CFBundlePrimaryIcon"] objectForKey:@"CFBundleIconFiles"] objectAtIndex:0]];
// Verify app can open custom URL scheme, open
NSURL *urlScheme = [NSURL URLWithString:@"instagram-stories://share"];
if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) {
// Assign background image asset and attribution link URL to pasteboard
//NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundVideo" : backgroundVideo}];
NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundVideo" : backgroundVideo, @"com.instagram.sharedSticker.stickerImage" : UIImagePNGRepresentation(appIcon)}];
NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]};
// This call is iOS 10+, can use 'setItems' depending on what versions you support
[[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions]; [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil];
} else {
// Handle older app versions or app not installed case
}
You can add Instagram Stories to any image or video in your Story. Whenever you want to add a Sticker tap on the Stickers icon. The app will show you a range of stickers that you can select from to add to your image or video.
The most obvious things to check right away are:
Does your asset match these criteria:
Uri to an image asset (JPG, PNG) or video asset (H.264, H.265, WebM). Minimum dimensions 720x1280. Recommended image ratios 9:16 or 9:18. Videos can be 1080p and up to 20 seconds in duration. The Uri needs to be a content Uri to a local file on the device.
intent.setDataAndType(backgroundAssetUri, "*/*");
- the docs say that the second value of the function could be null, however I do not think that "*/*" is a valid mime-type: try with MEDIA_TYPE_VIDEO - Link to Docs intent.setDataAndType(backgroundAssetUri, MEDIA_TYPE_VIDEO);
MEDIA_TYPE_VIDEO added in API level 11
public static final int MEDIA_TYPE_VIDEO
Constant for the MEDIA_TYPE column indicating that file is a video file.
Constant Value: 3 (0x00000003)
Activity activity = getActivity(); activity.grantUriPermission("com.instagram.android", stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); if (activity.getPackageManager().resolveActivity(intent, 0) != null) { activity.startActivityForResult(intent, 0); }
This was a bug.
Facebook wrote: "They've added the functionality now to Android as well, so you should be able to send a background with a sticker now."
I tried the same approach as on Facebook's official documentation then tested on Huawai P9 Lite
(N), Huawai P20 Lite
(O) and Samsung S8
(O) - it only worked on Samsung S8
for still not known reasons. I gave up trying since, obviously, it's not working on most of the phones.
The most interesting thing is that sharing on the feed with same method worked just fine:
Intent intent = new Intent("com.instagram.share.ADD_TO_FEED"); //feed
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(image, "image/jpeg");
Uri image = getImageUri();
Activity activity = getActivity();
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
activity.startActivityForResult(intent, 0);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With