No Activity found to handle Intent com.instagram.share.ADD_TO_STORY

10

In our React Native app, we're trying to have our users share specific images straight to either feed or story depending on a selection within our view/component.

When we try to share using "com.instagram.share.ADD_TO_FEED" directly, it works perfectly in a consisten manner.

However when trying to share using "com.instagram.share.ADD_TO_STORY" directly we get the following error:

No Activity found to handle Intent { act=com.instagram.share.ADD_TO_STORY > typ=image/* flg=0x10000000 pkg=com.instagram.android (has extras) }

We've gotten it to work only with one device (specifically using a Samsung Note 8), but our other test devices all have that error pop up.

Here's our code:

@ReactMethod
public void shareWithInstagram(String fileName, String base64str, String mode, Callback callback,
        Callback secondCallback) {

    this.callback = callback;

    String type = "image/*";

    File media = saveImage(getReactApplicationContext(), fileName, base64str);

    if (isAppInstalled("com.instagram.android") == false) {
        callback.invoke("Sorry, instagram is not installed in your device.");
    } else {
        if (media.exists()) {
            Intent share = new Intent("com.instagram.share." + mode);
            share.setType(type);
            share.setPackage("com.instagram.android");
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
            Uri uri = Uri.fromFile(media);

            share.setDataAndType(uri, type);
            share.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            share.putExtra(Intent.EXTRA_STREAM, uri);
            Activity currentActivity = getCurrentActivity();

            if (currentActivity.getPackageManager().resolveActivity(share, 0) != null) {

                currentActivity.startActivityForResult(share, INSTAGRAM_SHARE_REQUEST);
            } else {
                callback.invoke("Sorry, an error ocurred.");
            }
        } else {
            callback.invoke("Sorry, image could not be loaded from disk.");
        }
    }

}
android
facebook
react-native
instagram

2 Answers

3

This is probably happening because the activity with the action com.instagram.share.ADD_TO_STORY has android:enabled="false" in Instagram manifest. The com.instagram.share.ADD_TO_FEED action activity does not have this.

You can see that sharing to the Story is also not available if you try to share an image from the gallery.

The solution is simple: you need to restart Instagram after you have logged in. Then it will become available. This is probably an Instagram precaution against showing multiple Instagram actions in app chooser if user actually does not use Instagram.


Now this becomes quite funny:

our other test devices all have that error pop up

..it happens because when you try it on another device, you just install Instagram, log into your testing account and start trying .. and it never works because you first need to restart the Instagram app! :)

answered on Stack Overflow Mar 15, 2019 by David Riha
1

For us it was the "type", it seems "image/*" isn't allowed.

Using "video/mp4" worked!

answered on Stack Overflow Sep 10, 2020 by tobidude

User contributions licensed under CC BY-SA 3.0