使Ionic应用程序出现在“分享”中列出并接收数据 [英] Make Ionic app appear in "Share" list and receive data

查看:227
本文介绍了使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工作。
这个问题是相关的,并提到了一种方法来为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.

还相关:

Also related:

  • 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.

更新

Update

全部答案只关注Android,我真的希望有人能指出我正确的iOS方向,因为我需要更多......

赏金

经过长时间的考虑,我已经结束了给予@Ghandi的赏金。虽然没有人能给出完整的答案,但他是唯一一个试图回答整个问题的人 - 包括iOS部分。我并没有期待一个完整的代码解决方案,只是Android和iOS正确方向的指针,这就是他最接近所有答案。我知道这是一个非常广泛的问题,我要感谢所有花时间回答和/或评论这个问题的人。

Android


正如我在上面的问题中描述的那样,你必须将这些行添加到 AndroidManifest.xml 。 Android将使您的应用程序显示在共享列表中。您的应用收到的数据必须通过所谓的意图。为此,您可以使用 Ionic Native - Web Intent 。截至9.5.2017,由于Plugin Ionic Native使用不再存在,因此无法使用。然而,我在Github上创建了一个问题,我被告知下一个版本Ionic Native(我认为3.7.0)应该在接下来的两周内发布,应该通过使用插件。这解决了必须亲自玩Ionic Framework并简单地使用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共享菜单中添加应用程序的最佳链接是在共享菜单中列出该链接包括用于执行此操作的Apple文档以及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应用程序出现在“分享”中列出并接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆