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.");
}
}
}
For us it was the "type", it seems "image/*" isn't allowed.
Using "video/mp4" worked!
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>
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! :)
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