For some platform security reasons, Ubuntu Mobile currently does not provide for third-party developers to send text messages and call the interface, but in the actual application, we may need to send a short message or call. What shall we do at this time? We have described how to use URL dispatcher to invoke methods of third-party apps in the previous article, "Example using URL dispatcher." Here we use this method to show how to send short messages and make calls in our app.
First, we create the simplest "app with simple UI" template app and modify our "MAIN.QML" file as follows:
Import QtQuick 2.0import ubuntu.components 1.1import Ubuntu.Components.ListItems 0.1 as listitem/*! \brief MainView with a Label and Button Elements.*/mainview {//ObjectName for functional testing purposes (autopilot- QT5) ObjectName: "MainView"//note! ApplicationName needs to match the "name" field of the click Manifest ApplicationName: "Com.ubuntu.developer.liu-xiao-g Uo.phone "/* This property enables the application to change orientation when the device is rotated. The default is False. *///automaticorientation:true//Removes the old toolbar and enables new features of the new header. Usedeprecatedtoolbar:false width:units.gu (height:units.gu) page {title:i18n.tr ("Phone") function call (PhoneNumber) {qt.openurlexternally ("tel:///" + encodeURIComponent (PhoneNumber))} function SendMessage (phonenumber, text) {qt.openurlexternally ("message:///" + encodeURIComponent (phonenumber)}} Column {Spacing:units.gu (1) Anchors {margins:units.gu (2) Fill:parent} Row {Anchors.horizontalCenter:parent.horizontalCenter Label {anchors.verticalCenter:parent.verticalCenter text:i18n.tr (" Number: ")} TextField {Id:inputnumber Placeholderte XT: "Please type your phone number" text: "1111111111"}} Button {width:parent.width text:i18n.tr ("call") OnClicked: {C All (Inputnumber.text)}} listitem.divider {} Row {anchors . horizontalCenter:parent.horizontalCenter Label {anchors.verticalCenter:parent.vertic Alcenter text:i18n.tr ("Number:")} TextField {Id:inputnumber1 Placeholdertext: "Please type your phone number" text: "22222222222"} } TextEdit {Id:messagetext} Button {Width:parent.widt H text:i18n.tr ("Send Message") onclicked: {sendMessage (Inputnumber1.tex t)}}}}
The design of this application is very simple. Our UI is as follows:
We can call or send a text message by pressing the "call" or "Send Message" button by entering the number in the box above which you want to make or send a text message. Only SMS or phone applications are invoked to complete this action. From a security standpoint, this requires the user's interaction to be completed. It's very safe for the phone. We used the following code to do the work of URL dispatcher:
function call (PhoneNumber) { qt.openurlexternally ("tel:///" + encodeURIComponent (PhoneNumber)) } function SendMessage (phonenumber, text) { qt.openurlexternally ("message:///" + encodeURIComponent (PhoneNumber)) }
The complete code for the entire application can be found at the following address:
BZR Branch Lp:~liu-xiao-guo/debiantrial/phone
How to send text messages and make calls on your Ubuntu phone