openharmony 鸿蒙 js-apis-selectionInput-selectionExtensionContext

2026-08-25 浏览 (1)

@ohos.selectionInput.SelectionExtensionContext (Word Selection Extension Context)

SelectionExtensionContext is the context of SelectionExtensionAbility, which is inherited from ExtensionContext.

When a SelectionExtensionAbility component is instantiated, the system automatically creates the corresponding SelectionExtensionContext. You can use SelectionExtensionContext to start other abilities in the same application.

NOTE

  • The initial APIs of this module are supported since API version 24. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • This module is supported only on PCs/2-in-1 devices.

Modules to Import

import { SelectionExtensionContext } from '@kit.BasicServicesKit';

SelectionExtensionContext

System capability: SystemCapability.SelectionInput.Selection

Model constraint: This API can be used only in the stage model.

startAbility

startAbility(want: Want): Promise<void>

Starts an ability. This API uses a promise to return the result.

System capability: SystemCapability.SelectionInput.Selection

Model constraint: This API can be used only in the stage model.

Parameters

NameTypeMandatoryDescription
wantWantYesWant information of the ability to start, including the ability name and bundle name.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Ability Error Codes.

IDError Message
16000001The specified ability does not exist.
16000002Incorrect ability type.
16000004Cannot start an invisible component.
16000005The specified process does not have the permission.
16000006Cross-user operations are not allowed.
16000008The crowdtesting application expires.
16000009An ability cannot be started or stopped in Wukong mode.
16000010The call with the continuation and prepare continuation flag is forbidden.
16000011The context does not exist.
16000012The application is controlled.
16000013The application is controlled by EDM.
16000019No matching ability is found.
16000050Internal error.
16000053The ability is not on the top of the UI.
16000055Installation-free timed out.
16000061Operation not supported.
16000069The extension cannot start the third party application.
16000070The extension cannot start the service.
16000083The ExtensionAbility cannot start the ability due to system control.
16200001The caller has been released.

Example

import { SelectionExtensionAbility, BusinessError } from '@kit.BasicServicesKit';
import { rpc } from '@kit.IPCKit';
import { Want } from '@kit.AbilityKit';

class SelectionAbilityStub extends rpc.RemoteObject {
  constructor(des: string) {
    super(des);
  }
  onRemoteMessageRequest(
    code: number,
    data: rpc.MessageSequence,
    reply: rpc.MessageSequence,
    options: rpc.MessageOption
  ): boolean|Promise<boolean> {
    console.info(`onRemoteMessageRequest code: ${code}`);
    return true;
  }
}

class SelectionExtAbility extends SelectionExtensionAbility {
  onConnect(want: Want): rpc.RemoteObject {
    try {
      let wantAbility: Want = {
        bundleName: "com.selection.selectionapplication",
        abilityName: "EntryAbility",
      };
      this.context.startAbility(wantAbility).then(() => {
        console.info(`startAbility success`);
      }).catch((err: BusinessError) => {
        console.error(`startAbility error: ${err.code}, error message: ${err.message}`);
      })
    } catch (err) {
      console.error(`startAbility error: ${err.code}, error message: ${err.message}`);
    }
    return new SelectionAbilityStub('remote');
  }
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 errorcode-zlib

openharmony 鸿蒙 capi-oh-scan-scan-picturescanprogress

openharmony 鸿蒙 js-apis-screen-lock

openharmony 鸿蒙 capi-os-account-common-h

openharmony 鸿蒙 js-apis-screen-lock-sys

openharmony 鸿蒙 capi-oh-print-print-propertylist

openharmony 鸿蒙 capi-oh-scan

openharmony 鸿蒙 js-apis-system-device

openharmony 鸿蒙 errorcode-intelligentVoice

openharmony 鸿蒙 js-apis-request-sys

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/vXkBySrm