Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.");
        }
    }

}
like image 954
Rafa Ramírez Avatar asked Oct 09 '18 08:10

Rafa Ramírez


3 Answers

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

Using "video/mp4" worked!

like image 156
tobidude Avatar answered Nov 14 '22 07:11

tobidude


The AndroidManifest.xml file is probably missing an important element: <queries/>.

As the docs say

Specifies the set of other apps that an app intends to interact with. These other apps can be specified by package name, by intent signature, or by provider authority

In my case, after adding the following lines in the manifest file (inside manifest tag, not in application) everything started working.

<queries>
    <intent>
        <action android:name='com.instagram.share.ADD_TO_STORY' />
        <data android:mimeType='image/*' />
    </intent>
</queries>
like image 44
Sergi Mascaró Avatar answered Nov 14 '22 09:11

Sergi Mascaró


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! :)

like image 4
David Riha Avatar answered Nov 14 '22 08:11

David Riha