问题描述
我正在尝试让 Ionic 应用程序出现在分享"中.当用户单击共享按钮时的列表,例如图像.
I am trying to get an Ionic app to appear in the "Share" list when a user clicks the share button for example for an image.
据我所知,我必须添加类似
As far as I understand I have to add something like
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
到 AndroidManifest.xml
.我想我可以使用 cordova-custom-config 插件 来做到这一点.
然后我必须以某种方式处理这个意图,这对我来说很棘手.似乎目前唯一为意图维护的cordova插件是这个.我试过这样使用它:
to the AndroidManifest.xml
. That I can do using the cordova-custom-config plugin, I think.
I would then have to handle that intent somehow though and that is where it gets tricky for me. Seems like the only cordova plugin that is currently maintaned for intents is this one. I tried using it like this:
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
this.registerBroadcastReceiver();
});
}
private registerBroadcastReceiver(){
window.plugins.intentShim.registerBroadcastReceiver({
filterActions: [
'com.darryncampbell.cordova.plugin.broadcastIntent.ACTION'
]
},
function(intent) {
// Broadcast received
console.log('Received Intent: ' + JSON.stringify(intent.extras));
}
);
}
但是这样我会收到一个错误,即 window.plugins 未定义.我真的不知道如何将它与 Ionic 集成.
But this way I am getting an error that window.plugins is undefined. I don't really know how I would integrate this with Ionic.
此外,这仅适用于 Android,我希望也适用于 iOS.This SO question 是相关的,并提到了一种为 iOS 执行此操作的方法,但是它大约有 4 年的历史(链接的 iOS 部分 5 年)并且答案中为 Android 指定的项目 webintent 甚至不再存在.
Also this only works for Android, I would like to have that work for iOS too. This SO question is related and mentions a way to do it for iOS, but it's about 4 years old (the linked iOS parts 5 years) and the project webintent specified for Android in the answer doesn't even exist anymore.
如果有人可以在这里帮助我,那就太好了.
Would be great if someone could help me out here.
也相关:
- Cordova 从其他应用程序接收共享数据 - 使用过时的插件,
window.plugins
,Android 专用. - 将网址发送到ionic android app via webintents from another app - 使用过时的插件,
window.plugins
,Android 特有的.
- Cordova receive shared data from other app - Uses outdated plugin,
window.plugins
, Android specific. - Sending url to ionic android app via webintents from another app - Uses outdated plugin,
window.plugins
, Android specific.
更新
所有答案都只针对 Android,我真的希望有人可以为我指出 iOS 的正确方向,因为我更需要它......
赏金
经过长时间的考虑,我决定将赏金交给@Ghandi.虽然没有人能给出完整的答案,但他是唯一一个试图回答整个问题的人——包括 iOS 部分.我没想到会有完整的代码解决方案,只是为 Android 和 iOS 指明了正确方向,而这正是他最接近所有答案的地方.我知道这是一个非常广泛的问题,我要感谢所有花时间回答和/或评论这个问题的人.
安卓
正如我在上面的问题中已经描述的那样,您必须将这些行添加到 AndroidManifest.xml
.然后,Android 将使您的应用出现在共享列表中.您的应用收到的数据必须通过所谓的 Intent一个>.为此,您可以使用 Ionic Native - Web Intent.从 9.5.2017 开始,这将无法正常工作,因为 Ionic Native 正在使用的插件不再存在.然而,我在 Github 上创建了一个 issue,我被告知下一个版本应该在接下来的两周内发布的 Ionic Native(我认为 3.7.0)应该通过使用 plugin 在我上面的问题中已经提到过.这解决了您必须自己玩弄 Ionic 框架并简单地使用 Ionic Native 的问题.
Android
As I describe already in my question above, you have to add those lines to the AndroidManifest.xml
. Android will then make your app appear in the share list. The data that your app receives you'll have to handle via a so called Intent. To do so you can use Ionic Native - Web Intent. As of 9.5.2017 this would not work yet as the Plugin Ionic Native is using does not exist anymore. I have however created an issue on Github where I have been told that the next version of Ionic Native (I think 3.7.0), which should be released in the next two weeks, should fix this by using the plugin mentioned in my question above already. This resolves the issue of having to kinda play around the Ionic Framework yourself and simply being able to use Ionic Native.
iOS
在 iOS 中,它似乎有点棘手,而且在网络上也找不到它.最好按照@Ghandi 在下面的答案中提供的链接.
iOS
In iOS it seems to be a bit more tricky and also there is less to be found of it around the web. It's best you follow the link that @Ghandi provides in his answer below.
推荐答案
经过详细分析,我可以得出以下结论:
After some detailed analysis, this is what I could conclude:
在 Android 中,您可以使用 cordova-plugin-intent 将您的应用程序添加到共享列表中,如 这里.您还可以通过在活动中添加意图过滤器来实现此目的,如 这里
In Android, you could just get your application added in the share list using cordova-plugin-intent as described here. You can also achieve this by adding intent filter in the activity as described here
在 iOS 中,这有点棘手,因为没有直接的插件或现成的解决方案可以实现这一点.但与在 iOS 共享菜单中添加应用程序相关的最佳链接是 在共享菜单中列出该链接包括执行此操作的苹果文档以及 Info.plist 中的一些调整以实现此目的.
In iOS, this is bit tricky as there are no straight forward plugins or readymade solution available to achieve this. But the best possible link i could get related to adding app in iOS share menu is getting listed in share menu The link includes apple documentation to do this and also some tweaking in Info.plist to acheive this.
这是我能想到的最佳答案.希望能帮助到你.干杯.
This is the best possible answer I could think of. Hope it helps. Cheers.
这篇关于让 Ionic 应用出现在“分享"中列出和接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!