【发布时间】:2017-09-28 11:13:19
【问题描述】:
当用户单击图像的共享按钮时,我试图让 Ionic 应用程序出现在“共享”列表中。
据我所知,我必须添加类似
<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 plugin 来做到这一点。
然后我必须以某种方式处理这个意图,这对我来说很棘手。似乎目前唯一为意图维护的科尔多瓦插件是this one。我试过这样使用它:
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 集成。
此外,这仅适用于 Android,我希望也适用于 iOS。 This SO question 是相关的,并提到了一种为 iOS 执行此操作的方法,但它已有 4 年的历史(链接的 iOS 部分为 5 年),并且答案中为 Android 指定的项目 webintent 甚至不再存在。
如果有人可以在这里帮助我,那就太好了。
也相关:
-
Cordova receive shared data from other app - 使用过时的插件,
window.plugins,特定于 Android。 -
Sending url to ionic android app via webintents from another app - 使用过时的插件,
window.plugins,特定于 Android。
更新
所有答案都只针对 Android,我真的希望有人可以为我指出 iOS 的正确方向,因为我更需要它......
最终结论和赏金
赏金
经过长时间的考虑,我决定将赏金交给@Ghandi。虽然没有人能给出完整的答案,但他是唯一一个试图回答整个问题的人——包括 iOS 部分。我没想到会有完整的代码解决方案,只是为 Android 和 iOS 指明了正确方向,而这正是他最接近所有答案的地方。我知道这是一个非常广泛的问题,我要感谢所有花时间回答和/或评论这个问题的人。
对于其他试图完成同样事情的人,这是我对所有研究和答案的总结
安卓
正如我在上面的问题中已经描述的那样,您必须将这些行添加到AndroidManifest.xml。然后,Android 将使您的应用出现在共享列表中。您的应用收到的数据必须通过所谓的Intent 进行处理。为此,您可以使用Ionic Native - Web Intent。从 9.5.2017 开始,这将无法正常工作,因为 Ionic Native 正在使用的插件不再存在。然而,我创建了一个issue on Github,我被告知下一个版本的 Ionic Native(我认为是 3.7.0)应该在接下来的两周内发布,应该使用我在我的上面的问题已经。这解决了您必须自己玩弄 Ionic 框架并简单地使用 Ionic Native 的问题。
iOS
在 iOS 中,它似乎有点棘手,而且在网络上也找不到它。最好按照@Ghandi 在下面的答案中提供的链接。
【问题讨论】:
-
让我知道它是否有效..
-
谢谢,过几天试试。关于如何在 iOS 中执行此操作的任何想法?
-
@bergben 以下链接应该可以帮助您 - stackoverflow.com/questions/42384763/… stackoverflow.com/questions/13350857/… 特别是 devanshsadhotra 的 cmets
-
@bergben 就 ios 而言,不幸的是,据我所知,您没有现成的插件来实现这一目标
-
@bergben 您期望答案被接受的附加信息是什么?请介绍一下
标签: android ios cordova ionic-framework ionic3