Page 1 of 1

How to get mobile text messaging working

Posted: Wed Dec 14, 2022 11:02 am
by Hendricus
Dear LiveCoders,

I have been trying to get my app to trigger preparing a text message (SMS) on an android device. At first I tried with:

Code: Select all

put "This is a test text" into tMessage
put URLEncode(tMessage) into tMessage
launch url "sms:" & tMobile & "&body=" & tMessage
This starts the text messaging app on the android phone, selecting the name for the phone number in the tMobile variable, but it leaves the message empty. I have tried variations with the body parameter, to have a ';' instead of the '&' and other combinations. They didn't work. Then I came across the specific functions for this in the LiveCode Dictionary (mobileCanComposeTextMessage(), and mobileComposeTextMessage tMobile, tMessage). But these seem to fail too. With the following code I get the answer "Cannot send text messages" on my android phone when I press the button.

Code: Select all

on mouseUp
   if mobileCanComposeTextMessage() then 
      answer "Text Messages can be sent"
   else 
      answer "Cannot send text messages"
   end if
end mouseUp
Are there some settings for the standalone or elsewhere that are needed to get this to work?

Re: How to get mobile text messaging working

Posted: Wed Dec 14, 2022 11:35 am
by AndyP
Try changing this line

Code: Select all

launch url "sms:" & tMobile & "&body=" & tMessage
To

Code: Select all

launch url "sms:" & tMobile & "?body=" & tMessage
Notice the & was replaced with ?

I've not tested but I think this is the problem?

Re: How to get mobile text messaging working

Posted: Wed Dec 14, 2022 11:38 am
by Klaus
In any case you should add parentheses!

Code: Select all

launch url("sms:" & tMobile & "/body=" & tMessage)

Re: How to get mobile text messaging working

Posted: Wed Dec 14, 2022 12:35 pm
by Hendricus
Awesome. The code works perfectly like this:

Code: Select all

launch url("sms:" & tMobile & "?body=" & tMessage)
Thanks for the feedback. I still wonder why the mobileCanComposeTextMessage() doesn't work though. Anyone used this before?