FormEditExtensionContext

FormEditExtensionContext, inherited from UIExtensionContext, is the context of FormEditExtensionAbility.

NOTE

  • The initial APIs of this module are supported since API version 18. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • The APIs of this module can be used only in the stage model.

Modules to Import

import { FormEditExtensionAbility } from '@kit.FormKit';

FormEditExtensionContext

You can use FormEditExtensionContext to access specific FormEditExtensionAbility resources.

startSecondPage

startSecondPage(want: Want): Promise<AbilityResult>

Starts the widget provider page to be edited. This API uses a promise to return the result.

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

System capability: SystemCapability.Ability.Form

Parameters

Name Type Mandatory Description
want Want Yes Information about the editing page that needs to be started by the home screen of a third-party application.

Return value

Type Description
Promise<AbilityResult> Promise used to return the ability result.

Error codes

For details about the error codes, see Form Error Codes and Universal Error Codes.

ID Error Message
202 The application is not a system application.
16500050 An IPC connection error happened.
16501000 An internal functional error occurred.
16500100 Failed to obtain the configuration information.

Example

import { FormEditExtensionAbility } from '@kit.FormKit';
import { UIExtensionContentSession, Want } from '@kit.AbilityKit';

const TAG: string = '[testTag] ExampleFormEditExtensionAbility'

export default class ExampleFormEditAbility extends FormEditExtensionAbility {
  abilityName: string = 'FormEditSecPageAbility'

  onSessionCreate(want: Want, session: UIExtensionContentSession) {
    try {
      this.context.startSecondPage({
        bundleName: 'com.example.formEditDemo',
        parameters: {
          "secPageAbilityName": this.abilityName
        }

      }).then(data => {
        console.info(TAG, `startSecondPage result want: ${data.resultCode}`)
      });
    } catch (e) {
      console.error(TAG, `startSecondPage failed, code: ${e.code}, message: ${e.message}`)
      return
    }
  }
}

startUIAbility23+

startUIAbility(want: Want): Promise<void>

Starts UIAbility of the application to which a widget belongs. This API uses a promise to return the result.

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

System capability: SystemCapability.Ability.Form

Parameters

Name Type Mandatory Description
want Want Yes Want information of the UIAbility of the application.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Form Error Codes and Universal Error Codes.

ID Error Message
16500050 An IPC connection error happened.
16500100 Failed to obtain the configuration information.
16000130 The target UIAbility does not belong to the caller.
16501014 The form edit page is not in the foreground. The current operation is not supported.
16000121 The target component type is not a UIAbility.

Example

import { FormEditExtensionAbility } from '@kit.FormKit'
import { Want, UIExtensionContentSession } from '@kit.AbilityKit';

const TAG: string = '[testTag] ExampleFormEditExtensionAbility'

export default class ExampleFormEditAbility extends FormEditExtensionAbility {
  abilityName: string = 'FormEditSecPageAbility'

  onSessionCreate(want: Want, session: UIExtensionContentSession) {
    try {
      this.context.startUIAbility({
        abilityName: 'EntryAbility1',
      }).then(() => {
        console.info(TAG, `startUIAbility success`);
      });
    } catch (e) {
      console.error(TAG, `startUIAbility failed, code: ${e.code}, message: ${e.message}`);
      return
    }
  }
}