亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

OpenHarmony如何調(diào)用電話(huà)服務(wù)API撥打電話(huà)

 更新時(shí)間:2022年11月23日 09:32:02   作者:堅(jiān)果的博客  
OpenHarmony3.1版本標(biāo)準(zhǔn)系統(tǒng)增加了通話(huà)相關(guān)的聯(lián)系人應(yīng)用,來(lái)電應(yīng)用等,在系統(tǒng)服務(wù)層面電話(huà)相關(guān)功能也比較完善,這篇文章主要介紹了OpenHarmony如何調(diào)用電話(huà)服務(wù)API撥打電話(huà)

OpenHarmony電話(huà)服務(wù)開(kāi)發(fā)

電話(huà)服務(wù)系統(tǒng)提供了一系列的API用于撥打電話(huà)、獲取無(wú)線(xiàn)蜂窩網(wǎng)絡(luò)和SIM卡相關(guān)信息。

應(yīng)用可以通過(guò)調(diào)用API來(lái)獲取當(dāng)前注冊(cè)網(wǎng)絡(luò)名稱(chēng)、網(wǎng)絡(luò)服務(wù)狀態(tài)、信號(hào)強(qiáng)度以及SIM卡的相關(guān)信息,具體可參考獲取當(dāng)前蜂窩網(wǎng)絡(luò)信號(hào)信息開(kāi)發(fā)指導(dǎo)。

直接撥打電話(huà)需要系統(tǒng)權(quán)限ohos.permission.PLACE_CALL,建議應(yīng)用使用makeCall(),跳轉(zhuǎn)到撥號(hào)界面,并顯示撥號(hào)的號(hào)碼,具體可查看下面的演示。

OpenHarmony跳轉(zhuǎn)撥號(hào)界面

當(dāng)應(yīng)用需要跳轉(zhuǎn)到撥號(hào)界面,并顯示撥號(hào)的號(hào)碼時(shí),大家就可以來(lái)看這篇文章,當(dāng)開(kāi)發(fā)者調(diào)用makeCall接口時(shí),設(shè)備會(huì)自動(dòng)跳轉(zhuǎn)到撥號(hào)界面。和正常撥打電話(huà)一樣,用戶(hù)可以選擇卡1或卡2撥出。

先來(lái)看一下實(shí)現(xiàn)的效果。

接口說(shuō)明

call模塊為開(kāi)發(fā)者提供呼叫管理功能。observer模塊為開(kāi)發(fā)者提供通話(huà)業(yè)務(wù)狀態(tài)訂閱和取消訂閱功能。

  • call.hasVoiceCapability():能力獲取,表示是否具有語(yǔ)音功能。
  • call.makeCall()跳轉(zhuǎn)撥號(hào)界面,跳轉(zhuǎn)到撥號(hào)界面,并顯示撥號(hào)的號(hào)碼。
  • observer.on(‘callStateChange’):訂閱通話(huà)業(yè)務(wù)狀態(tài)變化,ohos.permission.READ_CALL_LOG (獲取通話(huà)號(hào)碼需要該權(quán)限)
  • observer.off(‘callStateChange’):取消訂閱通話(huà)業(yè)務(wù)狀態(tài)變化.

開(kāi)發(fā)步驟

1.import需要的模塊。

// import需要的模塊
import call from '@ohos.telephony.call';
import observer from '@ohos.telephony.observer';

2.調(diào)用hasVoiceCapability()接口獲取當(dāng)前設(shè)備呼叫能力,如果支持繼續(xù)下一步;如果不支持則無(wú)法發(fā)起呼叫。

// 調(diào)用查詢(xún)能力接口
let isSupport = call.hasVoiceCapability();
if (!isSupport) {
    console.log("not support voice capability, return.");
    return;
}

3.跳轉(zhuǎn)到撥號(hào)界面,并顯示撥號(hào)的號(hào)碼。

// 如果設(shè)備支持呼叫能力,則繼續(xù)跳轉(zhuǎn)到撥號(hào)界面,并顯示撥號(hào)的號(hào)碼
call.makeCall("13xxxx", (err)=> {
    if (!err) {
        console.log("make call success.");
    } else {
        console.log("make call fail, err is:" + JSON.stringify(err));
    }
});

4.(可選)訂閱通話(huà)業(yè)務(wù)狀態(tài)變化。

// 訂閱通話(huà)業(yè)務(wù)狀態(tài)變化(可選)
observer.on("callStateChange", (data) => {
    console.log("call state change, data is:" + JSON.stringify(data));
});

5.取消訂閱通話(huà)業(yè)務(wù)狀態(tài)變。

// 取消訂閱通話(huà)業(yè)務(wù)狀態(tài)變
observer.off("callStateChange", (data) => {
    console.log("call state change, data is:" + JSON.stringify(data));
});

完畢

最后附上完整代碼:

/*
 * Copyright (c) 2022 JianGuo 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.
 */
/**     
  * @ProjectName : nutsStudy
  * @FileName :  call
  * @Description : 文件描述 
 */
// import需要的模塊
import call from '@ohos.telephony.call';
import observer from '@ohos.telephony.observer';
@Entry
@Component
struct CAllTest{
  build(){
    Column(){
      Button("打電話(huà)").width(200).height(80) .fontSize(30).fontColor(Color.Orange).onClick(()=>{
        // 調(diào)用查詢(xún)能力接口
        let isSupport = call.hasVoiceCapability();
        if (!isSupport) {
          console.info(" support voice capability, return");
          return;
        }
        // 如果設(shè)備支持呼叫能力,則繼續(xù)跳轉(zhuǎn)到撥號(hào)界面,并顯示撥號(hào)的號(hào)碼
        call.makeCall("17752170152", (err)=> {
          if (!err) {
            console.info(" make call success.");
          } else {
            console.info("make call fail, err is:" + JSON.stringify(err));
          }
        });
      })
    }.width("100%").height("100%").justifyContent(FlexAlign.Center)
}
}

到此這篇關(guān)于OpenHarmony如何調(diào)用電話(huà)服務(wù)API撥打電話(huà)的文章就介紹到這了,更多相關(guān)OpenHarmony撥打電話(huà)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論