在我们的 React Native 应用中,我们试图让我们的用户根据我们的 View /组件中的选择直接将特定图像分享到提要或故事。
当我们尝试直接使用“com.instagram.share.ADD_TO_FEED”进行分享时,它以一致的方式完美运行。
但是,当尝试直接使用“com.instagram.share.ADD_TO_STORY”进行分享时,我们会收到以下错误:
No Activity found to handle Intent { act=com.instagram.share.ADD_TO_STORY > typ=image/* flg=0x10000000 pkg=com.instagram.android (has extras) }
我们让它只能在一台设备上工作(特别是使用三星 Note 8),但我们的其他测试设备都会弹出该错误。
这是我们的代码:
@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.");
}
}
}
最佳答案
AndroidManifest.xml
文件可能缺少一个重要元素:<queries/>
.
作为docs说
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
在我的例子中,在 list 文件中添加以下行后(在 manifest
标签内,而不是在 application
内)一切开始工作。
<queries>
<intent>
<action android:name='com.instagram.share.ADD_TO_STORY' />
<data android:mimeType='image/*' />
</intent>
</queries>
关于android - 找不到处理 Intent com.instagram.share.ADD_TO_STORY 的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52716819/