capacitor-community / proposals

Plugin and platform requests ✋
75 stars 2 forks source link

SendIntent (Android) #46

Open tavosansal opened 4 years ago

tavosansal commented 4 years ago

Plugin Request

Have a plugin that is able to handle share data in the capacitor applications for Android

Name: SendIntent Package: @capacitor-community/send-intent

Platform(s)

Existing Solutions

This is my current solution: https://github.com/tavosansal/capacitor-plugin-send-intent Works for Android. The main drawback is that there is no implementation right now for iOS. iOS needs a share target and some other things that I am not familiar with. I could use some help on how this could work so hit me up if you have ideas.

Description

The plugin allows you to expose a listener in your Javascript application for when another application sends data to your Capacitor application via the Android share menu or share sheet. This is useful if your Android application would like to receive data from other apps and your app can handle the shared data.

The SendIntent plugin exposes one event appSendActionIntent that receives a data object which contains the information received from the native intent verbatim.

See more: https://github.com/tavosansal/capacitor-plugin-send-intent#android-send-intent-plugin-for-capacitor

IT-MikeS commented 4 years ago

Maybe this can be integrated with #47 ?

carsten-klaffke commented 4 years ago

Hi! I also have a working solution for Android which covers URLs, text files and images. I also implemtented the iOS side, but it was heavily xCode configuration. This is my package: send-intent (iOS documentation will be added soon!) Please inform me if I can contribute or you need help with the iOS part.

tavosansal commented 4 years ago

Hello. It does seem like we are all working on basically the same thing so we should definitely join efforts. Anyone have ideas on what the best API would be? Im also curious as to how you did iOS @carsten-klaffke ? I thought you needed a "Share Extension" in your iOS project to be able to share into your application. But I might be wrong

carsten-klaffke commented 4 years ago

You are right, a share extension is needed for this. I just updated my project with explanations and code for iOS. I have to admit that it is a bit complicated (maybe unnecessarily...). The extension calls the main app with the shared params, the app puts those in a store and triggers the plugin to look them up.

tavosansal commented 4 years ago

@carsten-klaffke yeah that is exactly what I was picturing for iOS...it's so dang convoluted haha. But I don't see any other way to make this work for iOS. Thanks for adding that. I am curious about your API for listening for the event. Is the thought that you would periodically call Plugins.SendIntent.checkSendIntentReceived()? or does this get triggered by the plugin somehow?

carsten-klaffke commented 4 years ago

I registered an event in the client and then triggered it in iOS: window.addEventListener("sendIntentReceived", () => { Plugins.SendIntent.checkSendIntentReceived().then((result: any) => { if (result.text) { ... } }); }) In Plugin.swift: @objc open func eval(){ self.bridge.eval(js: "window.dispatchEvent(new Event('sendIntentReceived'))"); }

marwonline commented 3 years ago

(I know this thread is already a bit old.)

I also tried to create a plugin to process incoming intents https://github.com/marwonline/capacitor-share-target . It's currently in an alpha/beta status and is able to handle single and multiple images, files, videos or text on Android.

However, iOS support is a very hard one. I had working iOS code in a "Share Extension" bundled to one specific app; but make it available via the Capacitor plugin runtime was not possible for me. There are some open questions I could not find an answer for:

If someone is more experienced in iOS development than me, feel free to contribute on the issue.

riderx commented 2 years ago

@tavosansal i added your plugin to awesome-capacitor if that is useful please take time to star the repo as well :)

ebanDev commented 9 months ago

Any update on this?