上下文工具类的方法有哪些?

上下文工具类的方法

HarmonyOS
2024-08-07 09:16:16
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
妙蛙菜籽油

上下文工具类主要包括应用上下文属性applicationContext和实况窗点击跳转的构造方法buildWantAgent。applicationContext在EntryAbility创建时完成初始化,用于获取应用中配置的文字、图片资源。buildWantAgent用于配置实况窗中点击跳转相关的属性。

// ContextUtil.ets
export class ContextUtil {
  public static applicationContext: abilityCommon.ApplicationContext;

  public static async buildWantAgent(): Promise<Want> {
    const wantAgentInfo: WantAgent.WantAgentInfo = {
      wants: [
        {
          bundleName: ContextUtil.applicationContext.applicationInfo.name,
          abilityName: 'EntryAbility',
        } as Want
      ],
      operationType: WantAgent.OperationType.START_ABILITIES,
      requestCode: 0,
      wantAgentFlags: [WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
    };
    try {
      const wantAgent = await WantAgent.getWantAgent(wantAgentInfo);
      Logger.info('getWantAgent success! wantAgent: %{public}s', JSON.stringify(wantAgent));
      return wantAgent;
    } catch (e) {
      const err: BusinessError = e as BusinessError;
      Logger.error('getWantAgent failed! err: %{public}s', err.message);
      throw e as Error;
    }
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-08-07 11:22:46
相关问题
无法从static上下文引用非static方法
10981浏览 • 1回复 待解决
HarmonyOS 获取上下文Context
978浏览 • 1回复 待解决
如何获取应用上下文Context?
1453浏览 • 1回复 待解决
从卡片启动时候上下文会不会变?
384浏览 • 0回复 待解决
如何在普通ets文件中获取上下文Context
1930浏览 • 1回复 待解决
把arkts运行时,当成 JS上下文
2589浏览 • 1回复 待解决