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 Want from '@ohos.application.Want'; 16import { Log } from '../utils/Log'; 17import { startAbility } from '../utils/AbilityUtils'; 18import type { MenuOperation } from './MenuOperation'; 19import { MenuContext } from './MenuContext'; 20import { ItemDataSource } from '../vm/ItemDataSource'; 21 22const TAG = "ShareMenuOperation" 23 24export class ShareMenuOperation implements MenuOperation { 25 private menuContext: MenuContext; 26 private uris: string[]; 27 28 constructor(menuContext: MenuContext) { 29 this.menuContext = menuContext; 30 } 31 32 doAction(): void { 33 if (this.menuContext == null) { 34 Log.warn(TAG, 'menuContext is null, return'); 35 return; 36 } 37 let dataSource: ItemDataSource = this.menuContext.dataSource; 38 if (dataSource == null) { 39 return; 40 } 41 this.uris = dataSource.getSelectedUris(); 42 this.shareFileAsset(); 43 } 44 45 shareFileAsset() { 46 Log.info(TAG, 'shareFileAsset'); 47 let want: Want = { 48 'action': 'com.huawei.intent.action.hwCHOOSER', 49 'parameters': { 50 'ability.want.params.INTENT': { 51 'action': 'ability.intent.SEND_DATA', 52 'type': '*/*', 53 'parameters': { 54 'ability.params.stream': this.uris 55 } 56 } 57 } 58 } 59 startAbility(want); 60 } 61}