HarmonyOS Web组件中怎么拨打电话、跳转应用商店?

HarmonyOS
2024-12-17 13:26:15
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

拨打电话demo:

import web_webview from ‘@ohos.web.webview’;
import call from ‘@ohos.telephony.call’;
import { BusinessError } from ‘@ohos.base’;

@Entry
@Component
struct WebComponent {
webviewController: web_webview.WebviewController = new web_webview.WebviewController();

build() {
Column() {
Web({ src: $rawfile(‘call.html’), controller: this.webviewController})
.onLoadIntercept((event) => {
if (event) {
let url: string = event.data.getRequestUrl();
// 判断链接是否为拨号链接
if (url.indexOf(‘tel://’) === 0) {
call.makeCall(url.substring(6),(err: BusinessError) => {
if (!err) {
console.log(“make call success.”);
} else {
console.log(“make call fail, err is:” + JSON.stringify(err));
}
});
return true;
}
}
return false;
})
}
}
}
call.html:
<!DOCTYPE html> <html> <body> <div> <a href="tel://10086">拨打电话</a> </div> </body> </html>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.

跳转应用商店demo:

import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';

@Entry
@Component
struct Index {
  @State appId: string = 要跳转的AppID;
  controller: TextInputController = new TextInputController();
  build() {
    Row() {
      Column() {
        TextInput({ text: this.appId, placeholder: '请输入应用的appId', controller: this.controller })
          .width('90%')
          .onChange((value: string) => {
            this.appId = value
          })
        Button('点击跳转到HarmonyOS版应用市场详情页面')
          .margin({top: 50})
          .onClick(()=>{
            const want: Want = {
              uri: `store://appgallery.huawei.com/app/ id=${this.appId}`
            };
            const context = getContext(this) as common.UIAbilityContext;
            context.startAbility(want).then(()=>{ 
              //拉起成功
            }).catch(()=>{
              // 拉起失败
            });
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
分享
微博
QQ
微信
回复
2024-12-17 16:10:00


相关问题
web如何拉起鸿蒙拨打电话的功能
255浏览 • 0回复 待解决
HarmonyOS 拨打电话功能
746浏览 • 1回复 待解决
HarmonyOS 如何调用拨打电话界面
1059浏览 • 1回复 待解决
HarmonyOS 拨打电话系统能力
1546浏览 • 1回复 待解决
HarmonyOS web组件打电话功能
710浏览 • 1回复 待解决
HarmonyOS 如何直接调起拨打电话
1131浏览 • 1回复 待解决
申请拨打电话权限无效
6956浏览 • 1回复 待解决
HarmonyOS APP能否直接进行拨打电话
728浏览 • 1回复 待解决
HarmonyOS 判断是否有拨打电话权限
1009浏览 • 1回复 待解决
HarmonyOS有没有拨打电话的相关资料
1377浏览 • 1回复 待解决
如何跳转通讯录 、 打电话
2757浏览 • 1回复 待解决
ets怎么跳转应用商店
4380浏览 • 1回复 待解决
HarmonyOS 跳转应用商店
580浏览 • 1回复 待解决
HarmonyOS 跳转应用商店下载更新
1066浏览 • 1回复 待解决
HarmonyOS 如何跳转应用商店下载应用
513浏览 • 1回复 待解决
HarmonyOS 如何跳转应用商店
645浏览 • 1回复 待解决