1 个回答

参考示例如下:

export class Contact {
  contactsName: string;
  telephone: number;

  constructor(contactsName: string, telephone: number) {
    this.contactsName = contactsName;
    this.telephone = telephone;
  }
}

@Entry
@Component
struct JumpMessage {
  private context = getContext(this) as common.UIAbilityContext

  startMMSAbilityExplicit() {
    // 这里完善联系人和号码
    let params: Array<Object> = [new Contact("张三", 123456)];
    let want: Want = {
      bundleName: "com.ohos.mms",
      abilityName: "com.ohos.mms.MainAbility",
      parameters: {
        contactObjects: JSON.stringify(params),
        pageFlag: "conversation",
        // 这里填写短信内容
        content: "我才是测试内容"
      }
    };
    this.context.startAbilityForResult(want).then((data) => {
      console.log("Success" + JSON.stringify(data))
    }).catch(() => {
      console.log("error")
    })
  }

  build() {
    Row() {
      Column() {
        Button(
          '发送短信'
        )
          .onClick(() => {
            this.startMMSAbilityExplicit();
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}

参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V5/faqs-ability-56-V5

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进