怎么在Ubuntu手机上发送短信及拨打电话

159 篇文章 2 订阅
137 篇文章 1 订阅

由于一些平台安全性的原因,Ubuntu手机目前暂时没有提供供第三方开发者发送短信及拨打电话的接口,但是在实际的应用中,我们也许会需要用到发送短信息或拨打电话。这个时候我们怎么办呢?我们在前面的文章“使用URL dispatcher的范例”中已经介绍了如何使用url dispatcher来调用第三方应用的方法。这里我们用该方法来展示如何在我们的应用中发送短信息及拨打电话。


首先,我们创建一个最简单的“App with Simple UI”模版应用,并修改我们的“main.qml”文件如下:


import QtQuick 2.0
import Ubuntu.Components 1.1
import 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



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值