HarmonyOS 5 - 新闻应用 - 系统分享
HarmonyOS 5 新闻应用 - 系统分享功能实现案例
摘要
本文详细介绍了在 HarmonyOS 5.0 新闻应用中实现系统分享功能的过程。通过使用 BarButton 组件和 systemShare 模块,实现了新闻链接的分享功能。
```javascript
BarButton({ icon: $r('sys.media.ohos_ic_public_share') })
.onClick(() => {
// 系统分享
const data = new systemShare.SharedData({
utd: uniformTypeDescriptor.UniformDataType.HYPERLINK,
title: 'NewsAPP',
content: ' `https://edition.cnn.com/` '
})
const controller = new systemShare.ShareController(data)
const ctx = this.getUIContext().getHostContext() as common.UIAbilityContext
controller.show(ctx, {
previewMode: systemShare.SharePreviewMode.DETAIL,
selectionMode: systemShare.SelectionMode.SINGLE
})
})
```
查看原文
HarmonyOS 5 News Application - System Sharing Function Implementation Case
Summary
This article details the implementation of the system sharing function in a HarmonyOS 5.0 news application. By using the BarButton component and the systemShare module, the sharing function of news links is achieved.<p>BarButton({ icon: $r('sys.media.ohos_ic_public_share') })
.onClick(() => {
// system share
const data = new systemShare.SharedData({
utd: uniformTypeDescriptor.UniformDataType.HYPERLINK,
title: 'NewsAPP',
content: ' `https://edition.cnn.com/` '
})
const controller = new systemShare.ShareController(data)
const ctx = this.getUIContext().getHostContext() as common.UIAbilityContext
controller.show(ctx, {
previewMode: systemShare.SharePreviewMode.DETAIL,
selectionMode: systemShare.SelectionMode.SINGLE
})
})