cordova-plugin-openwith icon indicating copy to clipboard operation
cordova-plugin-openwith copied to clipboard

How do I get this receiving a URL from a browser?

Open bedfl2016 opened this issue 4 years ago • 15 comments

How do I get this plugin receiving a URL from a browser?

bedfl2016 avatar Apr 11 '20 17:04 bedfl2016

Any luck?

MrXyfir avatar May 11 '20 02:05 MrXyfir

For iOS, add

<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>10</integer>

to your share extension .plist file under NSExtensionActivationRule section

EternallLight avatar May 11 '20 08:05 EternallLight

Thank you, is there a way to do this on android?

bedfl2016 avatar May 11 '20 12:05 bedfl2016

For Android, paste the following into your AndroidManifest.xml file:

            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="*/*" />
            </intent-filter>

This will make your app accept any type of files, including links. If you need to restrict to links only, examine what mime is coming when you're sharing links with the configuration above and them replace / with what you found. It will probably be text/plain.

EternallLight avatar May 11 '20 14:05 EternallLight

Ended up using https://github.com/missive/cordova-plugin-openwith and setup was super easy. Make sure to add via the git repo.

Not sure how it differs from Eternal's which it was forked from...

MrXyfir avatar May 11 '20 15:05 MrXyfir

Ok thanks for the help! I am going to look at the github link!

bedfl2016 avatar May 11 '20 16:05 bedfl2016

Thanks @MrXyfir !!! That worked PERFECTLY (the missive plugin) - I've been trying for TWO HOURS to get something to recognize plain text shares in Android and iOS - and NOTHING worked out of the box until I found your link to the missive plugin.

For the record, here is how I added it:

cordova plugin add https://github.com/missive/cordova-plugin-openwith.git \
  --variable ANDROID_MIME_TYPE="text/*" \
  --variable IOS_URL_SCHEME=myversesapp \
  --variable IOS_UNIFORM_TYPE_IDENTIFIER=public.plain-text \
  --variable IOS_BUNDLE_IDENTIFIER=com.josiahbryan.myverses

On Android, the item in intent.items[0] is:

{
    data: "lorem ipsum",
    type: "text/plain"
}

On iOS 13, the same intent.items[0] comes as:

{
    data: "lorem ipsum",
    type: "public.text"
    // other misc iOS-specific keys here, but nothing I cared about
}

If only I had tried that plugin two hours ago LOL - anyway, thanks!!

josiahbryan avatar May 17 '20 21:05 josiahbryan

@josiahbryan 2 hours? Rookie numbers! I spent like two days trying to get these stupid plugins to work! Glad I could help though.

MrXyfir avatar May 18 '20 03:05 MrXyfir

@EternallLight or anyone else who knows - Can you elaborate on how to make this plugin receive urls from a specific site - i.e. universal links? I would like my iOS app to open a url that is sent in whatsapp/facebook/mail etc - i.e. www.mysite.com/product/1234 and open the relevant page in my app. I was able to do it for android with tons of intent-filters and I would like to do the same for iOS, or at least partially. My config.xml can be seen here (you can scroll up and down to see how many intents I have added): https://github.com/IsraelHikingMap/Site/blob/9fef9192788a042aaee594854969a99b059ba1da/IsraelHiking.Web/config.xml#L133L143

Can any of you elaborate on the equivalent in iOS? Do I need to add some lines like the following to my ShareExtension-Info.plist file using the config.xml file?

<edit-config target="NSExtensionActivationRule" file="ShareExtension-Info.plist" mode="merge">
    <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
    <integer>10</integer>
</edit-config>

Any help would be appreciated.

HarelM avatar Jul 28 '20 14:07 HarelM

@HarelM That's not what this plugin is for. You need a plugin specifically for universal links like https://github.com/GEDYSIntraWare/cordova-universal-links-plugin which is a fork of the original deprecated plugin https://github.com/nordnet/cordova-universal-links-plugin

There are many forks available so you have to test and find one that works for you.

MrXyfir avatar Jul 28 '20 16:07 MrXyfir

@MrXyfir It works for android, also I found this information on predicate so I think it's possible for ios too :-) https://developer.apple.com/forums/thread/75628

HarelM avatar Jul 28 '20 17:07 HarelM

related: https://github.com/j3k0/cordova-plugin-openwith/issues/117

j-d-carmichael avatar Jul 08 '21 14:07 j-d-carmichael

For Android, paste the following into your AndroidManifest.xml file:

            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SEND_MULTIPLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="*/*" />
            </intent-filter>

This will make your app accept any type of files, including links. If you need to restrict to links only, examine what mime is coming when you're sharing links with the configuration above and them replace / with what you found. It will probably be text/plain.

I tried all mimeTypes but nothing is working. even with */* I am unable to retrieve URL or Text. Images and Videos are working fine.

Saqib92 avatar Aug 21 '21 11:08 Saqib92

I gave up on cordova and use capacitor js instea: https://capacitorjs.com/

Everything works out of the box very well.

There is 1 share plugin that works well except for sharing images: https://github.com/carsten-klaffke/send-intent

The only drawback beween cordova and capacitorjs so far has been the lack of good status bar support. In cordova they manage to push the view down.. in capacitor you have to make use of the safari safe zones with CSS.. other that that though it all just worked out of the box so far very well.

j-d-carmichael avatar Aug 22 '21 07:08 j-d-carmichael

on android try: https://github.com/j3k0/cordova-plugin-openwith/issues/27#issuecomment-1219905212

alextapia007 avatar Aug 26 '22 15:08 alextapia007