j3k0 / cordova-plugin-openwith

Get your Cordova App in the O.S. "Share" menu on iOS and Android
MIT License
137 stars 114 forks source link

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

Open bedfl2016 opened 4 years ago

bedfl2016 commented 4 years ago

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

MrXyfir commented 4 years ago

Any luck?

EternallLight commented 4 years ago

For iOS, add

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

to your share extension .plist file under NSExtensionActivationRule section

bedfl2016 commented 4 years ago

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

EternallLight commented 4 years ago

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.

MrXyfir commented 4 years ago

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

bedfl2016 commented 4 years ago

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

josiahbryan commented 4 years ago

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!!

MrXyfir commented 4 years ago

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

HarelM commented 4 years ago

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

MrXyfir commented 4 years ago

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

HarelM commented 4 years ago

@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

j-d-carmichael commented 3 years ago

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

Saqib92 commented 3 years ago

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.

j-d-carmichael commented 3 years ago

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.

alextapia007 commented 2 years ago

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