HarmonyOS 一个非系统app,要怎么实现发短信(跳转到短信)

let options: sms.SendMessageOptions = {
  slotId: 0,
  content: content,
  destinationHost: phoneNumber.toString(),
  serviceCenter: phoneNumber.toString(),
  destinationPort: 1000,
  // sendCallback: sendCallback,
  // deliveryCallback: deliveryCallback
};
sms.sendShortMessage(options, (err: BusinessError) => {
  console.log(`callback: err->${JSON.stringify(err)}`);
});
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

这个方法要权限,权限必须是系统应用不能满足需求。

HarmonyOS
2025-01-09 16:29:52
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

参考示例如下:

Button("跳转到短信").onClick((event: ClickEvent) => {
  let context = getContext(this) as common.UIAbilityContext;

  class info {
    contactName: string
    telephone: string

    constructor() {
      this.contactName = "刚跑"
      this.telephone = '123'
    }
  }

  // class want
  let contactInfo: Array<Object> = new Array()
  contactInfo[0] = new info();
  let want: Want = {
    bundleName: 'com.ohos.mms',
    abilityName: 'com.ohos.mms.MainAbility',
    parameters: {
      contactObjects: JSON.stringify(contactInfo),
      content: "内容",
      pageFlag: 'conversation'
    }
  };
  context.startAbility(want)
    .then(() => {
    })
    .catch((err: BusinessError) => {
      console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`);
    });
}).margin(10)
  • 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.
分享
微博
QQ
微信
回复
2025-01-09 18:07:53


相关问题
HarmonyOS 如何跳转到系统发短信界面?
709浏览 • 1回复 待解决
HarmonyOS如何跳转到发短信页面
1230浏览 • 1回复 待解决
如何跳转到系统发送短信页面
2820浏览 • 1回复 待解决
根据次开发多端部署开发短信页面
1761浏览 • 1回复 待解决
HarmonyOS app怎么跳转到系统设置?
991浏览 • 1回复 待解决
HarmonyOS 如何调用短信应用发送短信
631浏览 • 1回复 待解决
HarmonyOS 怎么跳转到系统页面
644浏览 • 1回复 待解决
HarmonyOS 拉起短信页面
873浏览 • 1回复 待解决
HarmonyOS 短信校验控件
391浏览 • 1回复 待解决
如何从app跳转到系统相机
5918浏览 • 1回复 已解决
如何实现跳转到系统设置
2382浏览 • 1回复 待解决