怎麼在Ubuntu手機上傳送簡訊及撥打到電話,ubuntu傳送簡訊
由於一些平台安全性的原因,Ubuntu手機目前暫時沒有提供供第三方開發人員傳送簡訊及撥打到電話的介面,但是在實際的應用中,我們也許會需要用到傳送簡訊息或撥打到電話。這個時候我們怎麼辦呢?我們在前面的文章“使用URL dispatcher的範例”中已經介紹了如何使用url dispatcher來調用第三方應用的方法。這裡我們用該方法來展示如何在我們的應用中傳送簡訊息及撥打到電話。
首先,我們建立一個最簡單的“App with Simple UI”模版應用,並修改我們的“main.qml”檔案如下:
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-guo.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(50) height: units.gu(75) 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 placeholderText: "please type your phone number" text: "1111111111" } } Button { width: parent.width text: i18n.tr("Call") onClicked: { call(inputnumber.text) } } ListItem.Divider {} Row { anchors.horizontalCenter: parent.horizontalCenter Label { anchors.verticalCenter: parent.verticalCenter text: i18n.tr("Number: ") } TextField { id: inputnumber1 placeholderText: "please type your phone number" text: "22222222222" } } TextEdit { id: messageText } Button { width: parent.width text: i18n.tr("Send Message") onClicked: { sendMessage(inputnumber1.text) } } } }}
這個應用的設計非常簡單。我們的UI如下:
我們在上面的號碼輸入框中輸入自己想要撥打或傳送簡訊的號碼,按下“Call”或“Send Message”按鈕,就可以撥打到電話或傳送簡訊了。只不過簡訊或電話的應用被調用起來來完成這個動作。從安全的角度來說,這個需要使用者的互動才可以完成。對手機是非常安全的。我們使用了如下的代碼來完成url dispatcher的工作:
function call(phonenumber) { Qt.openUrlExternally("tel:///" + encodeURIComponent(phonenumber)) } function sendMessage(phonenumber, text) { Qt.openUrlExternally("message:///" + encodeURIComponent(phonenumber)) }
整個應用的完整代碼在如下的地址可以找到:
bzr branch lp:~liu-xiao-guo/debiantrial/phone