Share video and sticker Image to Instagram Story on Android

风格不统一 提交于 2019-12-01 17:35:58

The most obvious things to check right away are:

  1. 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.

  2. 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)

  1. And finally - have you tested starting the activity as in the example:
    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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!