diff --git a/zh-cn/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md b/zh-cn/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md index c00b39e2c60fe5edf6631160dff33c4fba0f2074..98908a1b1657f4bc1893d6faa8c7fab8ab243fc2 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inner-application-serviceExtensionContext.md @@ -734,6 +734,234 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\ } ``` +## ServiceExtensionContext.startAbilityAsCaller10+ + +starAbilityAsCaller(want: Want, callback: AsyncCallback): void; + +使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用callback异步回调。 + +使用规则: + - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 + - 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 + - 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md) + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**系统API**: 此接口为系统接口,三方应用不支持调用。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000012 | The application is controlled. | +| 16000013 | The application is controlled by EDM. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) + +**示例:** + +```ts +import extension from '@ohos.app.ability.ServiceExtensionAbility'; +import Want from '@ohos.app.ability.Want'; + +export default class EntryAbility extends extension { + onCreate(want, launchParam) { + // want包含启动该应用的Caller信息 + let localWant: Want = want; + localWant.bundleName = 'com.example.demo'; + localWant.moduleName = 'entry'; + localWant.abilityName = 'TestAbility'; + + // 使用启动方的Caller身份信息启动新Ability + this.context.startAbilityAsCaller(localWant, (err) => { + if (err && err.code != 0) { + console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); + } else { + console.log('startAbilityAsCaller success.'); + } + }) + } +} + +``` + +## UIAbiliServiceExtensionContexttyContext.startAbilityAsCaller10+ + +startAbilityAsCaller(want: Want, options: StartOptions, callback: AsyncCallback): void; + +使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用callback异步回调。 + +使用规则: + - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 + - 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 + - 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md) + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**系统API**: 此接口为系统接口,三方应用不支持调用。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 | +| options | [StartOptions](js-apis-app-ability-startOptions.md) | 是 | 启动Ability所携带的参数。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000012 | The application is controlled. | +| 16000013 | The application is controlled by EDM. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) + +**示例:** + +```ts +import extension from '@ohos.app.ability.ServiceExtensionAbility'; +import Want from '@ohos.app.ability.Want'; + +export default class EntryAbility extends extension { + onCreate(want, launchParam) { + // want包含启动该应用的Caller信息 + let localWant: Want = want; + localWant.bundleName = 'com.example.demo'; + localWant.moduleName = 'entry'; + localWant.abilityName = 'TestAbility'; + + let option: StartOptions = { + displayId: 0 + } + + // 使用启动方的Caller身份信息启动新Ability + this.context.startAbilityAsCaller(localWant, option, (err) => { + if (err && err.code != 0) { + console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); + } else { + console.log('startAbilityAsCaller success.'); + } + }) + } +} + +``` + +## ServiceExtensionContext.startAbilityAsCaller10+ + +startAbilityAsCaller(want: Want, options?: StartOptions): Promise; + +使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用Promise异步回调。 + +使用规则: + - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 + - 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 + - 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md) + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**系统API**: 此接口为系统接口,三方应用不支持调用。 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 | +| options | [StartOptions](js-apis-app-ability-startOptions.md) | 是 | 启动Ability所携带的参数。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | Promise对象。无返回结果的Promise对象。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000012 | The application is controlled. | +| 16000013 | The application is controlled by EDM. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) + +**示例:** + +```ts +import extension from '@ohos.app.ability.ServiceExtensionAbility'; +import Want from '@ohos.app.ability.Want'; + +export default class EntryAbility extends extension { + onCreate(want, launchParam) { + // want包含启动该应用的Caller信息 + let localWant: Want = want; + localWant.bundleName = 'com.example.demo'; + localWant.moduleName = 'entry'; + localWant.abilityName = 'TestAbility'; + + let option: StartOptions = { + displayId: 0 + } + + // 使用启动方的Caller身份信息启动新Ability + this.context.startAbilityAsCaller(localWant, option) + .then(() => { + console.log('startAbilityAsCaller success.'); + }) + .catch((err) => { + console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); + }) + } +} + +``` + ## ServiceExtensionContext.stopServiceExtensionAbility stopServiceExtensionAbility(want: Want, callback: AsyncCallback\): void; diff --git a/zh-cn/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md b/zh-cn/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md index fc9ceea38bfdf45ad4ed37ed3714e92c515a908e..227a55aa00171fb10605e3a6378cf77c5b34b8b7 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inner-application-uiAbilityContext.md @@ -2792,6 +2792,228 @@ startAbilityByCallWithAccount(want: Want, accountId: number): Promise<Caller& } ``` +## UIAbilityContext.startAbilityAsCaller10+ + +starAbilityAsCaller(want: Want, callback: AsyncCallback): void; + +使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用callback异步回调。 + +使用规则: + - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 + - 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 + - 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md) + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000012 | The application is controlled. | +| 16000013 | The application is controlled by EDM. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) + +**示例:** + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + // want包含启动该应用的Caller信息 + let localWant: Want = want; + localWant.bundleName = 'com.example.demo'; + localWant.moduleName = 'entry'; + localWant.abilityName = 'TestAbility'; + + // 使用启动方的Caller身份信息启动新Ability + this.context.startAbilityAsCaller(localWant, (err) => { + if (err && err.code != 0) { + console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); + } else { + console.log('startAbilityAsCaller success.'); + } + }) + } +} + +``` + +## UIAbilityContext.startAbilityAsCaller10+ + +startAbilityAsCaller(want: Want, options: StartOptions, callback: AsyncCallback): void; + +使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用callback异步回调。 + +使用规则: + - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 + - 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 + - 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md) + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 | +| options | [StartOptions](js-apis-app-ability-startOptions.md) | 是 | 启动Ability所携带的参数。 | +| callback | AsyncCallback<void> | 是 | 回调函数。当启动Ability成功,err为undefined,否则为错误对象。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000012 | The application is controlled. | +| 16000013 | The application is controlled by EDM. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) + +**示例:** + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + // want包含启动该应用的Caller信息 + let localWant: Want = want; + localWant.bundleName = 'com.example.demo'; + localWant.moduleName = 'entry'; + localWant.abilityName = 'TestAbility'; + + let option: StartOptions = { + displayId: 0 + } + + // 使用启动方的Caller身份信息启动新Ability + this.context.startAbilityAsCaller(localWant, option, (err) => { + if (err && err.code != 0) { + console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); + } else { + console.log('startAbilityAsCaller success.'); + } + }) + } +} + +``` + +## UIAbilityContext.startAbilityAsCaller10+ + +startAbilityAsCaller(want: Want, options?: StartOptions): Promise; + +使用设置的caller信息启动一个Ability,caller信息由want携带,在系统服务层识别,Ability可以在onCreate生命周期的want参数中获取到caller信息。使用该接口启动一个Ability时,want的caller信息不会被当前自身的应用信息覆盖,系统服务层可获取到初始caller的信息。使用Promise异步回调。 + +使用规则: + - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 + - 跨应用场景下,目标Ability的exported属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 + - 组件启动规则详见:[组件启动规则(Stage模型)](../../application-models/component-startup-rules.md) + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| want | [Want](js-apis-application-want.md) | 是 | 启动Ability的want信息。 | +| options | [StartOptions](js-apis-app-ability-startOptions.md) | 是 | 启动Ability所携带的参数。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | Promise对象。无返回结果的Promise对象。 | + +**错误码:** + +| 错误码ID | 错误信息 | +| ------- | -------------------------------- | +| 16000001 | The specified ability does not exist. | +| 16000002 | Incorrect ability type. | +| 16000004 | Can not start invisible component. | +| 16000005 | The specified process does not have the permission. | +| 16000006 | Cross-user operations are not allowed. | +| 16000008 | The crowdtesting application expires. | +| 16000009 | An ability cannot be started or stopped in Wukong mode. | +| 16000010 | The call with the continuation flag is forbidden. | +| 16000011 | The context does not exist. | +| 16000012 | The application is controlled. | +| 16000013 | The application is controlled by EDM. | +| 16000050 | Internal error. | +| 16000053 | The ability is not on the top of the UI. | +| 16000055 | Installation-free timed out. | +| 16200001 | The caller has been released. | + +错误码详细介绍请参考[errcode-ability](../errorcodes/errorcode-ability.md) + +**示例:** + +```ts +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + // want包含启动该应用的Caller信息 + let localWant: Want = want; + localWant.bundleName = 'com.example.demo'; + localWant.moduleName = 'entry'; + localWant.abilityName = 'TestAbility'; + + let option: StartOptions = { + displayId: 0 + } + + // 使用启动方的Caller身份信息启动新Ability + this.context.startAbilityAsCaller(localWant, option) + .then(() => { + console.log('startAbilityAsCaller success.'); + }) + .catch((err) => { + console.error('startAbilityAsCaller failed, err:' + JSON.stringify(err)); + }) + } +} + +``` + ## UIAbilityContext.reportDrawnCompleted10+ reportDrawnCompleted(callback: AsyncCallback\): void;