Send link with WhatsApp

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Send link with WhatsApp

Post by trevix » Thu Dec 31, 2020 2:28 pm

LC 9.6.2
I've been trying to send a text link to WhatsApp, from iPhone and Android, using my LC App.

Code: Select all

on mouseUp
   --this is the text: <p>Ciao.</p><p><a href="https://www.segnapunto.it/">This is my link: www.segnapunto.it</a></p>
     put "<p>Ciao.</p><p><a href=" & quote & "https://www.segnapunto.it/" & quote & ">This is my link: www.segnapunto.it</a></p>" into tText
     if the environment = "mobile" then
          try
               mobileComposeHtmlMail "TestInvito",,,,tText
          catch errorParameter
               answer errorParameter
          end try
if the Platform <> "android" then --android does not return anything
               answer the result
          end if
     end if
end mouseUp
Both using "mobileComposeHtmlMail" or "mobileComposeMail", on Android I get the dialog, where if I chose email, it works fine but if I chose WhatsApp nothing happens.
The only time it works with WhatsApp is if i add an attachment. But no text from the "body" get displayed.
I also tried to pu "whatsapp" on the Custom Url scheme of the Android standalone settings.

Is there something that I should know?
Thanks
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

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

Re: Send link with WhatsApp

Post by simon.schvartzman » Fri Jan 01, 2021 3:51 pm

Hi Trevix, teh code below is the one I use on one of my Apps to open the Share options (including WhatsApp) on both Android and iPhone.

I guess you can try/customize it with your data.

Code: Select all

try 
      if the platform is "iPhone" then
         -- it is so easy on iPhone!!!
         put specialfolderpath("documents") & "/" & "spot.png" into tPath 
         export snapshot from group "Group 1" of card "Capture" with metadata theMetadataArray to file tPath as PNG 
         mergPopActivity "",tPath,"","" 
         if the result is "mergPopActivity: cancel" then
            exit to top
         end if
      else
         export snapshot from group "Group 1" of card "Capture" to image "AuxImg" as JPEG
         put  image "AuxImg" into tAttachment["data"]
         put "image/jpg" into tAttachment["type"]
         put "LuckroSpot" into tAttachment["name"]
         mobileComposeMail "Imagem capturada com LuckroSpot", ,,,, tAttachment
         -- next statement is needed due to Android bug (I guess is a bug)
         set the fullscreenmode of this stack to "showAll"
      end if
   catch e
      answer e
   end try 
Hope it helps
Simon
________________________________________
To ";" or not to ";" that is the question

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Send link with WhatsApp

Post by trevix » Fri Jan 01, 2021 4:30 pm

i think I did not explain my problem, that concerns only Android:
My goal is to give the user the chance to send a precompiled text with URL, both for Email and WhatsApp (very popular).

On Android,for WhatsApp, unless I put an attachment, LC mobileComposeMail (or mobileComposeHtmlMail) does not fire WhatsApp. Even then, no text appear, only the attachment.

Anyway I found a way:

Code: Select all

--if WhatsApp
          put "Go here: http://www.segnapunto.it" into tText
          put URLEncode(tText) into tText
          put "whatsapp://send?text=" & tText into theURL
        launch url theURL
--if Email
        PUT "<p>Go here: <br></p><a href=" & quote & "https://www.segnapunto.it" & quote && "rel=" & quote & "self" & quote & ">www.segnapunto.it</a></span>" into tText
        mobileComposeHtmlMail "SegnaPunto: Buono regalo", ,,, tText
    ---"New problem"
My "New problem" is that even asking to the user if he wants WhatsApp or Email, when he chose email, mobileComposeHtmlMail still show the OS windows where to chose how to share (mai,gMail, whatsapp,...). I don't understand why and how to force Email only (but with a html link).
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

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

Re: Send link with WhatsApp

Post by simon.schvartzman » Sat Jan 02, 2021 12:21 pm

Hi Trevix, I had this problem before, please have a look at this post viewtopic.php?f=53&t=32193 .

As you can see what you are getting is the expected result in Android, I'm sorry to say it is not what you would like to have but this is the way it is...
Simon
________________________________________
To ";" or not to ";" that is the question

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Send link with WhatsApp

Post by trevix » Sat Jan 02, 2021 12:58 pm

In that post Jacque wrote:
...If the user has selected a default app for the file type then the picker won't be displayed at all, the default app will open instead....
I wonder then, how can i select a default app for the file type, inside "mobileComposeMail", so as to force on Android the MailApp or whatsApp?
"set the fileType to creator & type" should do, but has WhatsApp a "creator & type"? What about Email (user could have, other app then the default Email program.
Will have to do some testing.
Any suggestion?
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

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

Re: Send link with WhatsApp

Post by simon.schvartzman » Sat Jan 02, 2021 1:11 pm

As far as I understand it the default App for the file type is to be selected on the device itself not on the LC environment.

You can try it following this instructions: https://www.androidauthority.com/change ... -2-633572/

Screen Shot 2021-01-02 at 09.08.00.png
Simon
________________________________________
To ";" or not to ";" that is the question

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Send link with WhatsApp

Post by jacque » Sat Jan 02, 2021 7:20 pm

The default app is a system-wide setting chosen by the user and can't be changed per app or by script. In fact, most users will already have a default app set, though I go out of my way to avoid that because I want to choose the app each time. If you were able to reset the user's default choice you'd have some pretty angry users.

I think the default app depends on the file extension. Creator and type codes were only for Mac OS 9 and are obsolete now.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Send link with WhatsApp

Post by simon.schvartzman » Sun Jan 03, 2021 1:42 pm

Trevix, if instead of WhatsApp a text message (SMS) is acceptable to you an option to acomplish your goal would be to send the message to a server and then have a script to forward it through SMS (I guess it could be done with WhatsApp as well but is more complex than pure SMS)...

Just and idea
Simon
________________________________________
To ";" or not to ";" that is the question

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Send link with WhatsApp

Post by trevix » Sun Jan 03, 2021 4:44 pm

In italy nobody uses sms anymore. Only security check (ha ha)
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

LucaJones
Posts: 3
Joined: Sat Jul 22, 2023 9:25 am
Location: Poland
Contact:

Re: Send link with WhatsApp

Post by LucaJones » Sat Jul 22, 2023 10:07 am

The issue you are facing is that despite giving the user the option to choose between whatsapp and email, the 'mobilecomposehtmlmail' function on android still shows the os window to select how to share, offering choices like gmail and whatsapp.
You want to force the email option but still use an html link. Unfortunately, without more control over the sharing behavior, it might not be possible to bypass the os window and directly send an html link via email.
Consider exploring alternative approaches, that offer more customization options for handling email functionality on android.
Hi, I am Luca

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

Re: Send link with WhatsApp

Post by FourthWorld » Tue Jan 09, 2024 6:00 am

qoumsel wrote:
Tue Jan 09, 2024 3:34 am
There are a few things you can consider to troubleshoot the issue:
Hi qoumsel. I'm curious, what was it about half-year old thread that compelled you to create an account here to reply to it?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”