1/** 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import { HiLog } from '../../../../../common/src/main/ets/util/HiLog'; 16 17const TAG = 'MmsService '; 18// mms 19const MMS_BUNDLE_NAME = 'com.ohos.mms'; 20const MMS_ABILITY_NAME = 'com.ohos.mms.MainAbility'; 21const MMS_ENTITIES = 'entity.system.home'; 22 23export default class MmsService { 24 static sendMessage(number: string, formatnum:string, name?: string) { 25 let params = []; 26 params.push({ 27 contactsName: name, 28 telephone: number, 29 telephoneFormat: formatnum 30 }); 31 this.jumpToMms(params); 32 } 33 34 // Switching to the SMS app 35 private static jumpToMms(params) { 36 let actionData: any = {}; 37 actionData.contactObjects = JSON.stringify(params); 38 actionData.pageFlag = 'conversation'; 39 let str = { 40 'bundleName': MMS_BUNDLE_NAME, 41 'abilityName': MMS_ABILITY_NAME, 42 'parameters': actionData, 43 'entities': [ 44 MMS_ENTITIES, 45 ] 46 }; 47 globalThis.context.startAbility(str).then((data) => { 48 HiLog.i(TAG, 'jumpToMms success.'); 49 }).catch((error) => { 50 HiLog.e(TAG, 'jumpToMms failed: %s', JSON.stringify(error.message)); 51 }) 52 } 53}