HarmonyOS 无法实现在分享方调起分享弹窗中显示被分享方应用的icon

该如何配置才能实现在分享方调起的分享弹窗中显示被分享目标应用的icon?

  1. 根据API文档【目标应用处理分享内容】配置无法实现在分享方调起分享弹窗中显示被分享方应用的icon。目标应用处理分享内容API:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/share-interface-description-V5
  2. 且在应用配置文件(src/main/module.json5)的skills配置中注册,配置actions为ohos.want.action.sendData;uris中添加了.jpg支持的数据类型。
  3. 在系统图库应用中选中一张jpg格式的图片,点击分享;分享弹窗中未能如预期一样显示被分享的目标应用icon。
HarmonyOS
2024-12-23 16:32:23
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

参考下此demo看能否实现效果,注意将图片路径改成自己的路径:

import common from '@ohos.app.ability.common';
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import systemShare from '@hms.collaboration.systemShare';
import promptAction from '@ohos.promptAction';

let storage = LocalStorage.getShared()
const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'

@Entry(storage)
@Component
struct Index {
  private context = getContext(this) as common.UIAbilityContext
  @State selectionMode: systemShare.SelectionMode = systemShare.SelectionMode.SINGLE;
  @State previewMode: systemShare.SharePreviewMode = systemShare.SharePreviewMode.DEFAULT;
  @State anchorType: 'id' | 'rect' = 'rect';
  @LocalStorageLink('viewId') viewId: string = "";

  build() {
    Stack() {
      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
        Button('分享 - 文本').margin({bottom:10})
          .onClick(() => {
            this.shareContent('hello word', this.context)
          })
        Button('分享 - 网站').margin({bottom:10})
          .onClick(() => {
            this.shareWebSite(this.context, 'www.harmonyos.com', 'HarmonyOS')
          })
        Button('分享 - 单个图片').margin({bottom:10})
          .onClick(() => {
            //将路径改成自己图片的路径
            this.sharePicture('file://com.example.MyA/data/local/tmp/getScreenSize.jpeg', this.context)
          })
      }
    }.width('100%').height('100%')
  }

  // 分享文本
  shareContent(content: string, context: common.UIAbilityContext): void {
    const record = {
      utd: uniformTypeDescriptor.UniformDataType.PLAIN_TEXT,
      content: content,
    } as systemShare.SharedRecord;
    this.huaweiShare(record, context)
  }

  // 分享图片
  sharePicture(uri: string, context: common.UIAbilityContext): void {
    const record = {
      utd: uniformTypeDescriptor.UniformDataType.IMAGE,
      uri: uri,
    } as systemShare.SharedRecord;
    this.huaweiShare(record, context);
  }

  // 分享网站
  shareWebSite(context: common.UIAbilityContext, url: string, title: string, thumbnail?: Uint8Array): void {
    const record = {
      utd: uniformTypeDescriptor.UniformDataType.HYPERLINK,
      content: url,
      title: title,
      description: url,
      thumbnail: thumbnail!,
    } as systemShare.SharedRecord;
    this.huaweiShare(record, context)
  }

  private huaweiShare(record: systemShare.SharedRecord, context: common.UIAbilityContext): void {
    try {
      let data = new systemShare.SharedData(record);
      let controller: systemShare.ShareController = new systemShare.ShareController(data);
      controller.on('dismiss', () => {
        promptAction.showToast({
          message: 'Share panel disappeared'
        });
      });
      controller.show(context, {
        previewMode: systemShare.SharePreviewMode.DETAIL,
        selectionMode: systemShare.SelectionMode.SINGLE
      });
    } catch (e) {
      const error = e as Error;
      console.error('share error: ' + error.message);
    }
  }

  onBackPress(): boolean {
    this.context.eventHub.emit(EVENT_BACK_PRESS)
    return true
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
分享
微博
QQ
微信
回复
2024-12-23 20:30:01
相关问题
分享沙箱文件,应用分享单个文件
1876浏览 • 1回复 待解决
使用自定义弹窗实现分享弹窗
1334浏览 • 1回复 待解决
HarmonyOS 希望提供分享弹窗Demo
754浏览 • 1回复 待解决
HarmonyOS 分享功能如何实现
942浏览 • 1回复 待解决
HarmonyOS 分享功能可以分享到畅连吗
899浏览 • 1回复 待解决
HarmonyOS 文件分享如何指定应用
878浏览 • 1回复 待解决
鸿蒙如何实现分享功能
19123浏览 • 2回复 待解决
应用文件分享功能介绍
2580浏览 • 0回复 待解决
getDefaultCellularDataSlotIdSync实战分享
1060浏览 • 0回复 待解决
HarmonyOS 文件分享问题
860浏览 • 1回复 待解决
HarmonyOS 长截屏分享功能实现
713浏览 • 1回复 待解决