HarmonyOS 鸿蒙Next EmbeddedUIExtensionAbility

发布于 1周前 作者 eggper 来自 鸿蒙OS

HarmonyOS 鸿蒙Next EmbeddedUIExtensionAbility EmbeddedUIExtensionAbility有没有简单的可以运行的demo可以看下、https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/embeddeduiextensionability-V5这个实在太笼统了

4 回复

我在模拟机(手机)上运行,报错 Error: code = 100018

更多关于HarmonyOS 鸿蒙Next EmbeddedUIExtensionAbility的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


注意:仅支持在拥有多进程配置的设备上使用,设备是否支持可以通过如下命令查看(一般手机不支持,PC和pad支持)

param dump -a | grep persist.sys.abilityms.multi_process_model

image.png

Demo结构:

cke_3233.png

import { UIExtensionContentSession } from '@kit.AbilityKit';

let storage = LocalStorage.getShared()

@Entry(storage)
@Component
struct Extension {
  @State message: string = 'EmbeddedUIExtensionAbility Index';
  private session: UIExtensionContentSession | undefined = storage.get<UIExtensionContentSession>('session');

  build() {
    Column() {
      Text(this.message)
        .fontSize(20)
        .fontWeight(FontWeight.Bold)
      Button("terminateSelfWithResult").fontSize(20).onClick(() => {
        this.session?.terminateSelfWithResult({
          resultCode: 1,
          want: {
            bundleName: "com.example.myapplication_9gongge",
            abilityName: "ExampleEmbeddedAbility",
          }});
      })
    }.width('100%').height('100%')
  }
}
import { UIExtensionContentSession } from '@kit.AbilityKit';

let storage = LocalStorage.getShared()

@Entry(storage)
@Component
struct Extension {
  @State message: string = 'EmbeddedUIExtensionAbility Index';
  private session: UIExtensionContentSession | undefined = storage.get<UIExtensionContentSession>('session');

  build() {
    Column() {
      Text(this.message)
        .fontSize(20)
        .fontWeight(FontWeight.Bold)
      Button("terminateSelfWithResult").fontSize(20).onClick(() => {
        this.session?.terminateSelfWithResult({
          resultCode: 1,
          want: {
            bundleName: "com.example.myapplication_9gongge",
            abilityName: "ExampleEmbeddedAbility",
          }});
      })
    }.width('100%').height('100%')
  }
}
import { UIExtensionContentSession } from '@kit.AbilityKit';

let storage = LocalStorage.getShared()

@Entry(storage)
@Component
struct Extension {
  @State message: string = 'EmbeddedUIExtensionAbility Index';
  private session: UIExtensionContentSession | undefined = storage.get<UIExtensionContentSession>('session');

  build() {
    Column() {
      Text(this.message)
        .fontSize(20)
        .fontWeight(FontWeight.Bold)
      Button("terminateSelfWithResult").fontSize(20).onClick(() => {
        this.session?.terminateSelfWithResult({
          resultCode: 1,
          want: {
            bundleName: "com.example.myapplication_9gongge",
            abilityName: "ExampleEmbeddedAbility",
          }});
      })
    }.width('100%').height('100%')
  }
}
{
  "module": {
    "name": "entry",
    "type": "entry",
    "description": "$string:module_desc",
    "mainElement": "EntryAbility",
    "deviceTypes":  ["phone","tablet","2in1"],
    "deliveryWithInstall": true,
    "installationFree": false,
    "pages": "$profile:main_pages",
    "abilities": [
    {
        "name": "EntryAbility",
        "srcEntry": "./ets/entryability/EntryAbility.ets",
        "description": "$string:EntryAbility_desc",
        "icon": "$media:layered_image",
        "label": "$string:EntryAbility_label",
        "startWindowIcon" : "$media:startIcon",
        "startWindowBackground" : "$color:start_window_background"
          ,
        "exported": true
          ,
        "skills": [
          {
            "entities": [
              "entity.system.home"
            ],
            "actions": [
              "action.system.home"
            ]
          }
        ]
      }],
    "extensionAbilities": [
      {
        "name": "EntryBackupAbility",
        "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets",
        "type": "backup",
        "exported": false,
        "metadata": [
          {
            "name": "ohos.extension.backup",
            "resource": "$profile:backup_config"
          }
        ],
      },
      {
        "name": "EmbeddedUIExtAbility",
        "icon": "$media:EmbeddedUIExtAbilityIcon",
        "description": "EmbeddedUIExtAbility",
        "type": "embeddedUI",
        "srcEntry": "./ets/EmbeddedUIExtAbility/EmbeddedUIExtAbility.ets"
      }
    ],
    "requestPermissions": [
      {
        "name": "ohos.permission.WRITE_MEDIA",
        "usedScene": {
          "abilities": [
            "EntryAbility"
          ],
          "when": "inuse"
        },
        "reason": "$string:app_name"
      },
      {
        "name": "ohos.permission.MEDIA_LOCATION",
        "usedScene": {
          "abilities": [
            "EntryAbility"
          ],
          "when": "inuse"
        },
        "reason": "$string:app_name"
      },
      {
        "name": "ohos.permission.READ_IMAGEVIDEO",
        "usedScene": {
          "abilities": [
            "EntryAbility"
          ],
          "when": "inuse"
        },
        "reason": "$string:app_name"
      },
      {
        "name": "ohos.permission.WRITE_IMAGEVIDEO",
        "usedScene": {
          "abilities": [
            "EntryAbility"
          ],
          "when": "inuse"
        },
        "reason": "$string:app_name"
      },
      {
        "name": "ohos.permission.INTERNET",
        "reason": "$string:EntryAbility_desc",
        "usedScene": {
          "abilities": [
            "EntryAbility"
          ]
        }
      }
    ],

  }
}

HarmonyOS(鸿蒙)中的Next EmbeddedUIExtensionAbility是鸿蒙系统提供的一种能力,允许应用通过扩展UI的方式嵌入到其他应用中,实现更为丰富的交互和功能整合。

Next EmbeddedUIExtensionAbility主要用于构建更复杂、多层次的用户界面,它允许一个应用(宿主应用)在其界面内嵌入另一个应用(扩展应用)的UI组件。这种方式有助于提升用户体验,使得用户可以在不离开当前应用的情况下,访问和使用其他应用提供的特定功能或服务。

要实现Next EmbeddedUIExtensionAbility,开发者需要在鸿蒙系统的开发环境中,按照相关规范编写代码,并配置相应的manifest文件,以声明扩展UI的意图和所需的权限。此外,还需要确保宿主应用和扩展应用之间能够进行安全、有效的通信和数据交换。

值得注意的是,由于Next EmbeddedUIExtensionAbility涉及到多个应用之间的交互,因此在设计和实现时需要特别注意安全性和稳定性。开发者需要遵循鸿蒙系统的安全规范,确保数据的加密传输和存储,以及防止恶意应用的攻击。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部