Mobile Sharing an Image via Whatsapp

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Mobile Sharing an Image via Whatsapp

Post by simon.schvartzman » Thu Dec 13, 2018 2:26 pm

Hi, I was asked to develop an App (iOS and Android) that should be able to share an image via Whatsapp.

I know how to handle the image capture part of the App but I'm not aware of any functionality that could be used on LC to deliver the Whatsapp sharing functionality.

Any ideas?

Many thanks
Simon
________________________________________
To ";" or not to ";" that is the question

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Mobile Sharing an Image via Whatsapp

Post by FourthWorld » Thu Dec 13, 2018 6:20 pm

UrlSchemes were cross platform, and still the go-to mechanism for inter-app stuff on Android. Apple was pushing for an alternative, and may still be, but check their docs as UrlSchemes may still be well supported.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Mobile Sharing an Image via Whatsapp

Post by simon.schvartzman » Thu Dec 13, 2018 6:41 pm

Thanks @FourthWorld your suggestion sounds promising.

I did some search on WhatsApp FAQ and found the following:
Share Extension
Introduced in iOS 8.0, Share Extension provides a convenient way for any app to share content with other applications installed on user's iPhone. This is now the preferred way of sharing your content onto WhatsApp. This is as simple as creating an instance of UIActivityViewController and presenting it in your app. WhatsApp accepts the following types of content:
which seems to be the way to go and I wonder if there is any LC support for such "Share Extension". Wasn't able to find any mention to it on the documentation.

Best!
Simon
________________________________________
To ";" or not to ";" that is the question

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Mobile Sharing an Image via Whatsapp

Post by FourthWorld » Fri Dec 14, 2018 11:12 pm

It seems WhatsApp also supports a urlScheme:
https://faq.whatsapp.com/en/iphone/23559013
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Mobile Sharing an Image via Whatsapp

Post by simon.schvartzman » Sat Dec 15, 2018 11:33 am

@FourthWorld in fact the quote I added on my previous post was taken from the same link your are referencing.

But when I run

Code: Select all

   put "whatsapp://send?text=Hello%2C%20World!" into theURL
   put URL theURL into temp
   answer the result
I get
Invalid URL: "whatsapp://send?text=Hello%2C%20World!"
It happens both on the iPhone and in the desktop.

If I insert the same URL on my WebBrowser (both iPhone and desktop) the WhatsApp picking contact window opens as expected.

Not sure what am I doing wrong, have to do more testings...
Simon
________________________________________
To ";" or not to ";" that is the question

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Mobile Sharing an Image via Whatsapp

Post by simon.schvartzman » Mon Dec 17, 2018 1:39 am

Made some progress. The following code works fine on the desktop

Code: Select all

   put "whatsapp://send?text=Hello%2C%20World!" into theURL
   launch url theURL
   answer the result
but gives the following error on the iPhone
no association
Any hints to fix the error?

Thanks
Simon
________________________________________
To ";" or not to ";" that is the question

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Mobile Sharing an Image via Whatsapp

Post by bogs » Mon Dec 17, 2018 2:50 pm

Erm, well, the biggest problem might be that 'launch' isn't made for mobile.
Lc Dictionary wrote: launch
type
command
syntax

launch [documentPath with] applicationPath

summary
Starts up an application, optionally opening a document in the application.
introduced
1.0
OS
mac, windows, linux
platforms
desktop, server
Image

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Mobile Sharing an Image via Whatsapp

Post by simon.schvartzman » Mon Dec 17, 2018 2:57 pm

@bogs, thanks for your input but unless I'm missing something this is not my problem because I'm using "launch url" which is supposed to work on mobile as well
launch.jpg
Is there anything I'm not seeing?
Simon
________________________________________
To ";" or not to ";" that is the question

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Mobile Sharing an Image via Whatsapp

Post by bogs » Mon Dec 17, 2018 3:11 pm

simon.schvartzman wrote:
Mon Dec 17, 2018 2:57 pm
Is there anything I'm not seeing?
Nope, case of blindness on my part I'd say :oops:

I should add I don't do any mobile programming as well. If I had to guess (which I would :wink: ) I'd guess that the url isn't properly associated on the mobile device with another program.

A test *might* be changing -

Code: Select all

put "whatsapp://send?text=Hello%2C%20World!" into theURL
to a regular url on the mobile devices code, such as -

Code: Select all

put "https://www.duckduckgo.com" into theURL
and see if you get to the search engines website.

If that is the case, then you know the code your using is correct, and the address isn't associated properly on mobile becomes more likely. Least, that is what I would do. IF that doesn't work, I'm afraid you'll have to wait for someone that knows what they are talking about :oops:

*Edit - you might also add 'answer the result' with your original code to see what spits up on the mobile device (possibly effective, don't know the limits on mobile). According to the dictionary -
value
Name Type Description
the result

When launch url is called, LiveCode checks to see if an application is available to handle the URL. If no such application exists, the command returns "no association" in the result.


One other thing that is jumping out for me is the string your using in the address posted here

Code: Select all

text=Hello%2C%20World!"
is "text=Hello%2C%20World!" supposed to be "text=Hello%20%20World!" :?: If it is, that may also gum it up somehow.

Yes, I know it works on the desktop, but I've seen wierder stuff. Of course, it could be completely correct as well, I didn't take time to look it up :|
Image

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Mobile Sharing an Image via Whatsapp

Post by simon.schvartzman » Mon Dec 17, 2018 3:33 pm

@bogs many thanks for your suggestions, here I go

Code: Select all

put "http://www.livecode.com" into the URL
works fine.

Code: Select all

put "WhatsApp://send?text=Hello%20%20World!" into theURL
gave the same "no association" error as was giving with "2C" instead of "20" (nice catch)

regarding
*Edit - you might also add 'answer the result' with your original code to see what spits up on the mobile device (possibly effective, don't know the limits on mobile)
I already have it on my code

Code: Select all

on mouseUp
   put "WhatsApp://send?text=Hello%20%20World!" into theURL
   --put "http://www.livecode.com" into theURL
   launch url theURL
   answer the result
end mouseUp
and this is where I get the "no association" error on the mobile.

Anyone from LC there to clarify what can be done?
Simon
________________________________________
To ";" or not to ";" that is the question

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Mobile Sharing an Image via Whatsapp

Post by bogs » Mon Dec 17, 2018 3:44 pm

simon.schvartzman wrote:
Mon Dec 17, 2018 3:33 pm
[put "WhatsApp://send?text=Hello%20%20World!" into theURL]
gave the same "no association" error as was giving with "2C" instead of "20"
Isn't '%20' the url code for a space? If so, may want to eliminate one of those 2.

No association I am pretty sure means that the device doesn't have an associated program to handle whatsapp addresses, which would explain why it works on the desktop (but you already know this, I am merely thinking aloud as it were at this point).

I'm not sure that is something Lc can do anything about, as Lc polls the underlying OS for the associations.

For instance, I don't have whatsapp installed on, well, anything here. When I run your code, obviously nothing shows up since there is no association to whatsapp on the machine (desktop).

Lc can't fix something like the above, obviously. I assume your installation on the mobile device is the default way to go with whatsapp, barring rooting your phone or getting the apk from some other source or whatever.

If the mobile device did not make the whatsapp association properly, or if whatsapp itself doesn't do it properly on the device, that can be a sticky thing to resolve.
Image

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Mobile Sharing an Image via Whatsapp

Post by simon.schvartzman » Mon Dec 17, 2018 4:11 pm

In my last try I got rid of the "spaces" and used

Code: Select all

put "WhatsApp://send?text=Hello-World!" into theURL
and still no joy, same error.

You are correct about
I assume your installation on the mobile device is the default way to go with whatsapp..."
and as a matter of fact I'm able to share through whatsapp from many Apps installed on my phone using the familiar share screen:
wa.jpg
and I would assume a similar functionality should be able to be delivered on an LC developed App. Don't you think so?
Simon
________________________________________
To ";" or not to ";" that is the question

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Mobile Sharing an Image via Whatsapp

Post by bogs » Mon Dec 17, 2018 5:11 pm

In my last try I got rid of the "spaces" and used

Code: Select all

put "WhatsApp://send?text=Hello-World!" into theURL
and still no joy, same error.
Oh, I didn't think that having 2 spaces in the 'hello world' thing was messing it up, I was just thinking about dropping unnecessary things from the url that might lessen the complication.

Sorry for any confusion :oops:
simon.schvartzman wrote:
Mon Dec 17, 2018 4:11 pm
as a matter of fact I'm able to share through whatsapp from many Apps installed on my phone using the familiar share screen:
Image
and I would assume a similar functionality should be able to be delivered on an LC developed App. Don't you think so?
Well, that screen may be familiar to you, but it is my first time seeing it :D

The complete amount of gross ignorance I have with mobile is... well... complete. I have no idea what 'AirDrop' is, or how iOs does things in general.

Proceeding from my abysmal lack of knowledge, the picture (to me) looks like some kind of interpreter screen if you will, where you are picking the 'output' of some program, then using this screen to 'send' it to some other program (like whatsapp, mail, or facebook).

If that is the case (again, I don't know), then this 'AirDrop' is making the association for you for the particular program(s) you are 'sharing' through whatsapp, not because of some underlying association in the iOs OS, if you see the difference.

I am curious, though, if you can indeed add your Lc program to the list of AirDrops associated programs? Or alternately, if you couldn't take some form of output from your Lc program and use AirDrop to make the association for you?

Sorry, that is about as far as I can figure it with what I don't know, which is a LOT.

To answer your question specifically on something I *think* I know about, no, and your own testing should validate that.
Code: Select all

put "http://www.livecode.com" into the URL

works fine.
The reason it 'works' fine is because iOs has actual web addresses associated with opening a browser. It (iOs) just doesn't understand opening 'whatsapp' addresses, because apparently there is no association with that string.

Now, if there is a way for you to create such an association (I have no idea), then that would be the way to go.
Image

simon.schvartzman
Posts: 641
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Mobile Sharing an Image via Whatsapp

Post by simon.schvartzman » Mon Dec 17, 2018 8:29 pm

@bogs FYI English is not my mother tongue and therefore I could mislead you (and other readers) due to poor writing skills.

Having say so let me see if I can clarify some of your remarks
I have no idea what 'AirDrop' is,
Airdrop is just an Apple peer to peer communication scheme where both devices are close to each other (i.e. bluetooth distance)
where you are picking the 'output' of some program, then using this screen to 'send' it to some other program (like whatsapp, mail, or facebook).
You got it, that's exactly what it is about
...then this 'AirDrop' is making the association for you...
In my humble opinion AirDrop has nothing to do with it. It is just another way to share stuff.
I am curious, though, if you can indeed add your Lc program to the list of AirDrops associated programs?
That's not the idea
Or alternately, if you couldn't take some form of output from your Lc program and use AirDrop to make the association for you?
That's the idea (without the AirDrop part...)

Will see how the story ends up. Still waiting for some of the LC gurus to jump in.

Cheers
Simon
________________________________________
To ";" or not to ";" that is the question

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Mobile Sharing an Image via Whatsapp

Post by bogs » Mon Dec 17, 2018 10:48 pm

simon.schvartzman wrote:
Mon Dec 17, 2018 8:29 pm
@bogs FYI English is not my mother tongue and therefore I could mislead you (and other readers) due to poor writing skills.
I'd never have guessed, glad you clarified.
simon.schvartzman wrote:
Mon Dec 17, 2018 8:29 pm
You got it, that's exactly what it is about
...then this 'AirDrop' is making the association for you...
In my humble opinion AirDrop has nothing to do with it. It is just another way to share stuff.
Dunno, I can only go by what I see on the screen. To me, it looks like you have a set of programs to send (what looks like) something you brought into AirDrop. I'll take your word that it doesn't work that way, I sure have no experiences to say otherwise :D

Just out of curiousity, what happens when you enter the whatsapp address into the address bar of the web browser on the device? It is possible, I suppose, that the web browser could be a big enough fish for the 'share extension' you were talking about to pick the address out of the address bar, but I would be curious to know.

Since the only remaining things I can think of would be setting the association (dunno how), or if iOs had a version of the shell out (answer is no, according to the dictionary), or if someone knows how to direct a mobile program to directly launch another mobile program.

Good luck is all I can say at this point, maybe if we pray hard enough, Jacque will pop in with some magic. I'll start praying for you now...
Image
Image

Post Reply

Return to “Talking LiveCode”