How do I make a phone call on a mobile device?
In this lesson we will look at how to place a call from a LiveCode app that is running on a network enabled device.
Create a basic stack with a field for the phone number and a button to send
1) Create a new stack at your chosen mobile device size
2) Drag on a button and call it "Call"
3) Drag on a field and call it "number"
Add the following code to the 'call' button
Add this code to the call button
on mouseUp launch url "tel:" && field "number" put the result into field "number" end mouseUp
The launch URL functionality found in LiveCode has been extended to interface directly with mobile devices. To start a telephone call we simply pass the following string to the launch URL command:
tel: [Phone number]
So, to make a call to the LiveCode support line you would use the following:
Our final line of code would look like this:
launch url "tel:+448452198923"
In this example we are letting the user enter the phone number into the field we dragged onto our stack. We build the call string and pass it to the launch command. The second line of code simply puts the result of our call into the same field. If the string passed to launch command is incorrect you will see a "no association" message appear in the field.
Test our application
Simulators do not have the ability to place a phone call so you will get result string as message described above. You will need to build the app and deploy it to your phone to test.
The screenshots above are taken in the simulator (left) and from my iPhone (right)
On Android you will need to check the Internet permission in the Standalone Application Settings.