Reputation: 119
I want to share a video to instagram from my app, using my app logo as a sticker. I have been following this documentation, but the results is that everytime I try to share, instagram opens, shows me my video and the sticker, it freezes for about a second, and then the sticker dissapears, only leaving me with my video and no sticker to be seen, even after posting said video.
I have also read this question, where they stated that not being able to share a sticker with a video was a bug with android, but it should now be fixed. The image Im using for the sticker is 640x480 which is the recommended size according to documentation so I dont think is the image size either. I can only think Im sharing it wrong.
Here is my code:
Uri stickerAssetUri = Uri.parse("android.resource://" + R.class.getPackage().getName() + "/drawable/" + R.drawable.app_logo_sticker);
File media = new File(localFilePath);
Uri backgroundAssetUri = FileProvider.getUriForFile(getActivity(), getString(R.string.file_provider), media);
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(backgroundAssetUri, "video/mp4");
intent.putExtra("interactive_asset_uri", stickerAssetUri);
getActivity().grantUriPermission(
"com.instagram.android", stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (getActivity().getPackageManager().resolveActivity(intent, 0) != null) {
getActivity().startActivityForResult(intent, 0);
}
Upvotes: 1
Views: 188
Reputation: 119
The problem was the video file I was using for testing. The max duration for a background asset is 20 seconds, and while the file I was using was 20 seconds according the videoview, retrieving the actual duration of the video gave me 20333 milis which is over the limit specified in the documentation. I used a different file that actually meets the criteria and it works.
Upvotes: 2