2 Star 29 Fork 6

HarmonyOS_Samples/ShareKit_SampleCode_Clientdemo_ArkTS

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
VideoScenario.ets 2.34 KB
Copy Edit Raw Blame History
Your Name authored 2025-08-07 15:55 +08:00 . Share Kit
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
*/
import { systemShare } from '@kit.ShareKit';
import { uniformTypeDescriptor as utd } from '@kit.ArkData';
import { common } from '@kit.AbilityKit';
import { fileUri } from '@kit.CoreFileKit';
import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit';
import Logger from '../utils/Logger';
let logger = Logger.getLogger('[VideoScenario]');
@Component
export default struct VideoScenario {
private async share() {
const uiContext: UIContext = this.getUIContext();
const contextFaker: Context = uiContext.getHostContext() as Context;
let thumbnailPath = contextFaker.filesDir + '/exampleImage.jpg';
const imageSource: image.ImageSource = image.createImageSource(thumbnailPath);
const imagePacker: image.ImagePacker = image.createImagePacker();
let buffer: ArrayBuffer | undefined = undefined;
try {
buffer = await imagePacker.packToData(imageSource, {
format: 'image/jpeg',
quality: 30,
});
} catch (error) {
logger.error(`packToData error. Code: ${error?.code}, message: ${error?.message}`);
}
let filePath = contextFaker.filesDir + '/exampleImage.jpg';
let shareData: systemShare.SharedData = new systemShare.SharedData({
utd: utd.UniformDataType.VIDEO,
uri: fileUri.getUriFromPath(filePath),
title: 'Video title',
description: 'Video Description',
thumbnail: buffer ? new Uint8Array(buffer) : undefined,
});
let controller: systemShare.ShareController = new systemShare.ShareController(shareData);
const context: common.UIAbilityContext = uiContext.getHostContext() as common.UIAbilityContext;
controller.show(context, {
selectionMode: systemShare.SelectionMode.SINGLE,
previewMode: systemShare.SharePreviewMode.DETAIL,
}).then(() => {
logger.info('ShareController show success.');
}).catch((error: BusinessError) => {
logger.error(`ShareController show error. code: ${error?.code}, message: ${error?.message}`);
});
}
build() {
Row() {
Text($r('app.string.video_type'))
Button($r('app.string.share_btn'))
.onClick(() => this.share())
}
.width('100%')
.margin({ top: 12 })
.padding({ left: 20, right: 20 })
.justifyContent(FlexAlign.SpaceBetween)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/harmonyos_samples/share-kit_-sample-code_-clientdemo_-arkts.git
git@gitee.com:harmonyos_samples/share-kit_-sample-code_-clientdemo_-arkts.git
harmonyos_samples
share-kit_-sample-code_-clientdemo_-arkts
ShareKit_SampleCode_Clientdemo_ArkTS
master

Search