鸿蒙实战应用开发:【拨打电话】功能

概述

本示例通过输入电话,进行电话拨打,及电话相关信息的显示。

样例展示

涉及OpenHarmony技术特性

网络通信

基础信息

拨打电话

介绍

本示例使用call相关接口实现了拨打电话并显示电话相关信息的功能

效果预览

使用说明

1.输入电话号码后,点击电话按钮,进行拨打电话。

2.拨打电话后文本框会显示拨打是否成功,是否存在通话,通话状态,是否紧急号码,格式化后的电话号码。

工程目录

复制代码
entry/src/main/ets/
|---common
|   |---CallView.ets                   // 电话API
|---entryability
|   |---EntryAbility.ts
|---model
|   |---Logger.ts                      // 日志工具
|---pages
|   |---Index.ets                      // 首页

具体实现

  • 该示例展示拨打电话功能,dial方法拨打电话,可设置通话参数,hasCall方法判断是否存在通话,getCallState方法获取当前通话状态,isEmergencyPhoneNumber方法判断是否是紧急电话号码,formatPhoneNumber方法格式化电话号码,formatPhoneNumberToE164方法将电话号码格式化为E.164表示形式。

源码链接:[CallView.ets]

复制代码
/*

 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */



import Logger from '../model/Logger'

import call from '@ohos.telephony.call'



const TAG: string = `[CallView]`



@Component

export struct CallView {

  private on: Resource = $r('app.media.call_on')

  private off: Resource = $r('app.media.call_off')

  @State src: Resource = this.off

  @Link input: string

  @Link output: string



  build() {

    Column() {

      Image(this.src)

        .id('callImg')

        .width(70)

        .height(70)

        .onClick(() => {

          if (this.src == this.on) {

            this.src = this.off

          } else {

            this.output = ''

            this.src = this.on

            call.dialCall(this.input, (err, data) => {

              this.output = this.output + `dial: ${JSON.stringify(data)}` + '\n'

              Logger.info(`${TAG}, callback: dial err->${JSON.stringify(err)} data->${JSON.stringify(data)}`)

            })



            call.hasCall((err, data) => {

              this.output = this.output + `hasCall: ${JSON.stringify(data)}` + '\n'

              Logger.info(`${TAG}, callback: hasCall err->${JSON.stringify(err)} data->${JSON.stringify(data)}`)

            })



            call.getCallState((err, data) => {

              this.output = this.output + `getCallState: ${JSON.stringify(data)}` + '\n'

              Logger.info(`${TAG}, callback: getCallState err->${JSON.stringify(err)} data->${JSON.stringify(data)}`)

            })



            call.isEmergencyPhoneNumber(this.input, (err, data) => {

              this.output = this.output + `isEmergencyPhoneNumber: ${JSON.stringify(data)}` + '\n'

              Logger.info(`${TAG}, callback: isEmergencyPhoneNumber err->${JSON.stringify(err)} data->${JSON.stringify(data)}`)

            })



            call.formatPhoneNumber(this.input, (err, data) => {

              this.output = this.output + `formatPhoneNumber: ${JSON.stringify(data)}` + '\n'

              Logger.info(`${TAG}, callback: formatPhoneNumber err->${JSON.stringify(err)} data->${JSON.stringify(data)}`)

            })



            call.formatPhoneNumberToE164(this.input, "CN", (err, data) => {

              this.output = this.output + `formatPhoneNumberToE164: ${JSON.stringify(data)}` + '\n'

              Logger.info(`${TAG}, callback: formatPhoneNumberToE164 err->${JSON.stringify(err)} data->${JSON.stringify(data)}`)

            })

          }

        })

        .onFinish(() => {

          this.src = this.off

        })

    }

  }

}

鸿蒙OpenHarmony知识待更新👈点

最后呢,很多开发朋友不知道需要学习那些鸿蒙技术?鸿蒙开发岗位需要掌握那些核心技术点?为此鸿蒙的开发学习必须要系统性的进行。

而网上有关鸿蒙的开发资料非常的少,假如你想学好鸿蒙的应用开发与系统底层开发。你可以参考这份资料,少走很多弯路,节省没必要的麻烦。由两位前阿里高级研发工程师联合打造 的**《鸿蒙NEXT星河版OpenHarmony开发文档》** 里面内容包含了(**ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony****多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(Harmony NEXT)**技术知识点

如果你是一名Android、Java、前端等等开发人员,想要转入鸿蒙方向发展。可以直接领取这份资料辅助你的学习。下面是鸿蒙开发的学习路线图。

高清完整版请点击→《鸿蒙NEXT星河版开发学习文档》

针对鸿蒙成长路线打造的鸿蒙学习文档 。话不多说,我们直接看详细资料鸿蒙(OpenHarmony )学习手册(共计1236页)与鸿蒙(OpenHarmony )开发入门教学视频,帮助大家在技术的道路上更进一步。

《鸿蒙 (OpenHarmony)开发学习视频》

《鸿蒙生态应用开发V2.0白皮书》

《鸿蒙 (OpenHarmony)开发基础到实战手册》

获取这份鸿蒙星河版学习资料,请点击→ 《鸿蒙NEXT星河版开发学习文档》

OpenHarmony北向、南向开发环境搭建

《鸿蒙开发基础》

  1. ArkTS语言

  2. 安装DevEco Studio

  3. 运用你的第一个ArkTS应用

  4. ArkUI声明式UI开发

  5. .......

《鸿蒙开发进阶》

  1. Stage模型入门

  2. 网络管理

  3. 数据管理

  4. 电话服务

  5. 分布式应用开发

  6. 通知与窗口管理

  7. 多媒体技术

  8. 安全技能

  9. 任务管理

  10. WebGL

  11. 国际化开发

  12. 应用测试

  13. DFX面向未来设计

  14. 鸿蒙系统移植和裁剪定制

  15. ......

《鸿蒙开发实战》

  1. ArkTS实践

  2. UIAbility应用

  3. 网络案例

  4. ......

获取这份鸿蒙星河版学习资料,请点击→ 《鸿蒙NEXT星河版开发学习文档》

总结

鸿蒙---作为国家主力推送的国产操作系统。部分的高校已经取消了安卓课程,从而开设鸿蒙课程;企业纷纷跟进启动了鸿蒙研发

并且鸿蒙是完全具备无与伦比的机遇和潜力的;预计到年底将有 5,000 款的应用完成原生鸿蒙开发 ,未来将会支持 50 万款的应用 。那么这么多的应用需要开发,也就意味着需要有更多的鸿蒙人才鸿蒙开发工程师也将会迎来爆发式的增长,学习鸿蒙势在必行!

相关推荐
Storm-Shadow7 小时前
Android OpenGLES视频剪辑示例源码
android·opengles·视频滤镜
双桥wow7 小时前
android 堆栈打印
android
爱学习的大牛12312 小时前
使用C++开发Android .so库的优势与实践指南
android·.so·1024程序员节
摘星编程13 小时前
【成长纪实】HarmonyOS Next学习地图:新手避坑指南与核心知识点拆解
学习·华为·harmonyos·鸿蒙开发
文火冰糖的硅基工坊14 小时前
[人工智能-大模型-85]:大模型应用层 - AI/AR眼镜:华为智能眼镜、苹果智能眼镜、Google Glass智能眼镜的软硬件技术架构
人工智能·华为·ar
帅锅锅00715 小时前
SeLinux Type(类型)深度解析
android·操作系统
2501_9159214315 小时前
iOS混淆与IPA加固全流程(iOS混淆 IPA加固 Ipa Guard实战)
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者815 小时前
iOS 26 App 开发阶段性能优化 从多工具协作到数据驱动的实战体系
android·ios·小程序·uni-app·iphone·webview·1024程序员节
2501_9151063215 小时前
深入剖析 iOS 26 系统流畅度,多工具协同监控与性能优化实践
android·ios·性能优化·小程序·uni-app·cocoa·iphone