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

查看:26
本文介绍了使 Ionic 应用出现在“分享"中列出并接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 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.

还相关:

  • 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 方向,因为我更需要它...

赏金
经过长时间的考虑,我决定向@Gandi 提供赏金.虽然没有人能给出完整的答案,但他是唯一一个试图回答整个问题的人——包括 iOS 部分.我没想到一个完整的代码解决方案,只是一个指向 Android 和 iOS 正确方向的指针,这就是他在所有答案中最接近的.我知道这是一个非常广泛的问题,我要感谢所有花时间回答和/或评论这个问题的人.

安卓
正如我在上面的问题中已经描述的那样,您必须将这些行添加到 AndroidManifest.xml.然后,Android 将使您的应用出现在共享列表中.您的应用收到的数据必须通过所谓的 Intent.为此,您可以使用 Ionic Native - Web Intent.截至 2017 年 5 月 9 日,这将不起作用,因为 Ionic Native 使用的插件不再存在.然而,我在 Github 上创建了一个 问题,有人告诉我下一个版本应该在接下来的两周内发布的 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 中,它似乎有点棘手,而且在网络上也很少能找到它.最好点击@Gandi 在下面的回答中提供的链接.

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 应用出现在“分享"中列出并接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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