1e41f4b71Sopenharmony_ci# Context 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciContext模块提供了ability或application的上下文的能力,包括允许访问特定于应用程序的资源、请求和验证权限等。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> 本模块接口仅可在FA模型下使用。 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## 导入模块 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## 使用说明 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciContext对象是在featureAbility中创建实例,并通过featureAbility的[getContext](js-apis-ability-featureAbility.md#featureabilitygetcontext)接口返回,因此在使用Context时,必须导入@ohos.ability.featureAbility库。示例如下: 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 22e41f4b71Sopenharmony_ci```ts 23e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 26e41f4b71Sopenharmony_cicontext.getOrCreateLocalDir().then((data) => { 27e41f4b71Sopenharmony_ci console.info(`getOrCreateLocalDir data: ${JSON.stringify(data)}`); 28e41f4b71Sopenharmony_ci}); 29e41f4b71Sopenharmony_ci``` 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci## Context.getOrCreateLocalDir<sup>7+</sup> 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_cigetOrCreateLocalDir(callback: AsyncCallback\<string>): void 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci获取应用程序的本地根目录。使用callback异步回调。 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci如果是第一次调用,将创建目录。 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**参数:** 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 44e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------- | 45e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | 是 | 回调函数,返回应用程序的本地根目录。 | 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci**示例:** 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 50e41f4b71Sopenharmony_ci```ts 51e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 54e41f4b71Sopenharmony_cicontext.getOrCreateLocalDir((error, data)=>{ 55e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 56e41f4b71Sopenharmony_ci console.error(`getOrCreateLocalDir fail, error: ${JSON.stringify(error)}`); 57e41f4b71Sopenharmony_ci } else { 58e41f4b71Sopenharmony_ci console.log(`getOrCreateLocalDir success, data: ${JSON.stringify(data)}`); 59e41f4b71Sopenharmony_ci } 60e41f4b71Sopenharmony_ci}); 61e41f4b71Sopenharmony_ci``` 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci## Context.getOrCreateLocalDir<sup>7+</sup> 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_cigetOrCreateLocalDir(): Promise\<string> 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci获取应用程序的本地根目录。使用Promise异步回调。 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci如果是第一次调用,将创建目录。 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**返回值:** 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci| 类型 | 说明 | 78e41f4b71Sopenharmony_ci| ---------------- | ----------- | 79e41f4b71Sopenharmony_ci| Promise\<string> | Promise对象,返回应用程序的本地根目录。 | 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**示例:** 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 84e41f4b71Sopenharmony_ci```ts 85e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 88e41f4b71Sopenharmony_cicontext.getOrCreateLocalDir().then((data) => { 89e41f4b71Sopenharmony_ci console.info(`getOrCreateLocalDir data: ${JSON.stringify(data)}`); 90e41f4b71Sopenharmony_ci}); 91e41f4b71Sopenharmony_ci``` 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci## Context.verifyPermission<sup>7+</sup> 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_civerifyPermission(permission: string, options: PermissionOptions, callback: AsyncCallback\<number>): void 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci验证系统中运行的特定pid和uid是否允许指定的权限。使用callback异步回调。 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci**参数:** 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 104e41f4b71Sopenharmony_ci| ---------- | --------------------------------------- | ---- | -------------------- | 105e41f4b71Sopenharmony_ci| permission | string | 是 | 指定权限的名称。 | 106e41f4b71Sopenharmony_ci| options | [PermissionOptions](#permissionoptions7) | 是 | 权限选项。 | 107e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | 是 | 回调函数,返回权限验证结果,0有权限,-1无权限。 | 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**示例:** 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 112e41f4b71Sopenharmony_ci```ts 113e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 114e41f4b71Sopenharmony_ciimport bundle from '@ohos.bundle.bundleManager'; 115e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 118e41f4b71Sopenharmony_cibundle.getBundleInfo('com.context.test', 1, (err: BusinessError, datainfo: bundle.BundleInfo) =>{ 119e41f4b71Sopenharmony_ci context.verifyPermission('com.example.permission', {uid:datainfo.appInfo.uid}, (error, data) =>{ 120e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 121e41f4b71Sopenharmony_ci console.error(`verifyPermission fail, error: ${JSON.stringify(error)}`); 122e41f4b71Sopenharmony_ci } else { 123e41f4b71Sopenharmony_ci console.log(`verifyPermission success, data: ${JSON.stringify(data)}`); 124e41f4b71Sopenharmony_ci } 125e41f4b71Sopenharmony_ci }); 126e41f4b71Sopenharmony_ci}); 127e41f4b71Sopenharmony_ci``` 128e41f4b71Sopenharmony_ci示例代码中出现的getBundleInfo相关描述可参考对应[文档](js-apis-bundleManager.md)。 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci## Context.verifyPermission<sup>7+</sup> 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_civerifyPermission(permission: string, callback: AsyncCallback\<number>): void 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci验证系统中运行的当前pid和uid是否具有指定的权限。使用callback异步回调。 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**参数:** 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 143e41f4b71Sopenharmony_ci| ---------- | ---------------------- | ---- | -------------------- | 144e41f4b71Sopenharmony_ci| permission | string | 是 | 指定权限的名称。 | 145e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | 是 | 回调函数,返回权限验证结果,0有权限,-1无权限。 | 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci**示例:** 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 150e41f4b71Sopenharmony_ci```ts 151e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 154e41f4b71Sopenharmony_cicontext.verifyPermission('com.example.permission', (error, data) =>{ 155e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 156e41f4b71Sopenharmony_ci console.error(`verifyPermission fail, error: ${JSON.stringify(error)}`); 157e41f4b71Sopenharmony_ci } else { 158e41f4b71Sopenharmony_ci console.log(`verifyPermission success, data: ${JSON.stringify(data)}`); 159e41f4b71Sopenharmony_ci } 160e41f4b71Sopenharmony_ci}); 161e41f4b71Sopenharmony_ci``` 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci## Context.verifyPermission<sup>7+</sup> 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_civerifyPermission(permission: string, options?: PermissionOptions): Promise\<number> 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci验证系统中运行的特定pid和uid是否具有指定的权限。使用Promise异步回调。 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**参数:** 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 174e41f4b71Sopenharmony_ci| ---------- | --------------------------------------- | ---- | -------- | 175e41f4b71Sopenharmony_ci| permission | string | 是 | 指定权限的名称。 | 176e41f4b71Sopenharmony_ci| options | [PermissionOptions](#permissionoptions7) | 否 | 权限选项。 | 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**返回值:** 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci| 类型 | 说明 | 181e41f4b71Sopenharmony_ci| ---------------- | ---------------------------------- | 182e41f4b71Sopenharmony_ci| Promise\<number> | Promise对象,如果pid和uid具有权限,则使用0进行异步回调;否则使用-1回调。 | 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**示例:** 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 187e41f4b71Sopenharmony_ci```ts 188e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 191e41f4b71Sopenharmony_cicontext.verifyPermission('com.context.permission', {pid:1}).then((data) => { 192e41f4b71Sopenharmony_ci console.info(`verifyPermission data: ${JSON.stringify(data)}`); 193e41f4b71Sopenharmony_ci}); 194e41f4b71Sopenharmony_ci``` 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci## Context.requestPermissionsFromUser<sup>7+</sup> 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_cirequestPermissionsFromUser(permissions: Array\<string>, requestCode: number, resultCallback: AsyncCallback\<PermissionRequestResult>): void 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci从系统请求某些权限。使用callback异步回调。 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci**参数:** 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 209e41f4b71Sopenharmony_ci| -------------- | ---------------------------------------- | ---- | ----------------------------------- | 210e41f4b71Sopenharmony_ci| permissions | Array\<string> | 是 | 指示要请求的权限列表。此参数不能为null。 | 211e41f4b71Sopenharmony_ci| requestCode | number | 是 | 指示要传递给[PermissionRequestResult](#permissionrequestresult7)的请求代码。 | 212e41f4b71Sopenharmony_ci| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult7)> | 是 | 回调函数,返回授权结果信息。 | 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci**示例:** 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 217e41f4b71Sopenharmony_ci```ts 218e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 221e41f4b71Sopenharmony_cicontext.requestPermissionsFromUser( 222e41f4b71Sopenharmony_ci ['com.example.permission1', 223e41f4b71Sopenharmony_ci 'com.example.permission2', 224e41f4b71Sopenharmony_ci 'com.example.permission3', 225e41f4b71Sopenharmony_ci 'com.example.permission4', 226e41f4b71Sopenharmony_ci 'com.example.permission5'], 227e41f4b71Sopenharmony_ci 1, 228e41f4b71Sopenharmony_ci (error, data) => { 229e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 230e41f4b71Sopenharmony_ci console.error(`requestPermissionsFromUser fail, error: ${JSON.stringify(error)}`); 231e41f4b71Sopenharmony_ci } else { 232e41f4b71Sopenharmony_ci console.log(`requestPermissionsFromUser success, data: ${JSON.stringify(data)}`); 233e41f4b71Sopenharmony_ci } 234e41f4b71Sopenharmony_ci } 235e41f4b71Sopenharmony_ci); 236e41f4b71Sopenharmony_ci``` 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci## Context.requestPermissionsFromUser<sup>7+</sup> 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_cirequestPermissionsFromUser(permissions: Array\<string>, requestCode: number): Promise\<PermissionRequestResult> 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci从系统请求某些权限。使用Promise异步回调。 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci**参数:** 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 250e41f4b71Sopenharmony_ci| -------------- | ------------------- | ----- | -------------------------------------------- | 251e41f4b71Sopenharmony_ci| permissions | Array\<string> | 是 | 指示要请求的权限列表。此参数不能为null。 | 252e41f4b71Sopenharmony_ci| requestCode | number | 是 | 指示要传递给[PermissionRequestResult](#permissionrequestresult7)的请求代码。 | 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**返回值:** 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci| 类型 | 说明 | 257e41f4b71Sopenharmony_ci| ------------------------------------------------------------- | ---------------- | 258e41f4b71Sopenharmony_ci| Promise\<[PermissionRequestResult](#permissionrequestresult7)> | Promise对象,返回授权结果信息。 | 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci**示例:** 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 263e41f4b71Sopenharmony_ci```ts 264e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 267e41f4b71Sopenharmony_cicontext.requestPermissionsFromUser( 268e41f4b71Sopenharmony_ci ['com.example.permission1', 269e41f4b71Sopenharmony_ci 'com.example.permission2', 270e41f4b71Sopenharmony_ci 'com.example.permission3', 271e41f4b71Sopenharmony_ci 'com.example.permission4', 272e41f4b71Sopenharmony_ci 'com.example.permission5'], 273e41f4b71Sopenharmony_ci 1).then((data)=>{ 274e41f4b71Sopenharmony_ci console.info(`requestPermissionsFromUser data: ${JSON.stringify(data)}`); 275e41f4b71Sopenharmony_ci } 276e41f4b71Sopenharmony_ci); 277e41f4b71Sopenharmony_ci``` 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci## Context.getApplicationInfo<sup>7+</sup> 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_cigetApplicationInfo(callback: AsyncCallback\<ApplicationInfo>): void 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci获取有关当前应用程序的信息。使用callback异步回调。 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci**参数:** 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 292e41f4b71Sopenharmony_ci| -------- | ------------------------------- | ---- | ------------ | 293e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,返回当前应用程序的信息。 | 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci**示例:** 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 298e41f4b71Sopenharmony_ci```ts 299e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 302e41f4b71Sopenharmony_cicontext.getApplicationInfo((error, data) => { 303e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 304e41f4b71Sopenharmony_ci console.error(`getApplicationInfo fail, error: ${JSON.stringify(error)}`); 305e41f4b71Sopenharmony_ci } else { 306e41f4b71Sopenharmony_ci console.log(`getApplicationInfo success, data: ${JSON.stringify(data)}`); 307e41f4b71Sopenharmony_ci } 308e41f4b71Sopenharmony_ci}); 309e41f4b71Sopenharmony_ci``` 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci## Context.getApplicationInfo<sup>7+</sup> 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_cigetApplicationInfo(): Promise\<ApplicationInfo> 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci获取有关当前应用程序的信息。使用Promise异步回调。 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci**返回值:** 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_ci| 类型 | 说明 | 324e41f4b71Sopenharmony_ci| ------------------------- | --------- | 325e41f4b71Sopenharmony_ci| Promise\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)> | Promise对象,返回当前应用程序的信息。 | 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci**示例:** 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 330e41f4b71Sopenharmony_ci```ts 331e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 334e41f4b71Sopenharmony_cicontext.getApplicationInfo().then((data) => { 335e41f4b71Sopenharmony_ci console.info(`getApplicationInfo data: ${JSON.stringify(data)}`); 336e41f4b71Sopenharmony_ci}); 337e41f4b71Sopenharmony_ci``` 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci## Context.getBundleName<sup>7+</sup> 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_cigetBundleName(callback: AsyncCallback\<string>): void 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci获取当前ability的Bundle名称。使用callback异步回调。 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci**参数:** 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 352e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------ | 353e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | 是 | 回调函数,返回当前ability的Bundle名称。 | 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci**示例:** 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 358e41f4b71Sopenharmony_ci```ts 359e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 362e41f4b71Sopenharmony_cicontext.getBundleName((error, data) => { 363e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 364e41f4b71Sopenharmony_ci console.error(`getBundleName fail, error: ${JSON.stringify(error)}`); 365e41f4b71Sopenharmony_ci } else { 366e41f4b71Sopenharmony_ci console.log(`getBundleName success, data: ${JSON.stringify(data)}`); 367e41f4b71Sopenharmony_ci } 368e41f4b71Sopenharmony_ci}); 369e41f4b71Sopenharmony_ci``` 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci## Context.getBundleName<sup>7+</sup> 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_cigetBundleName(): Promise\<string> 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci获取当前ability的Bundle名称。使用Promise异步回调。 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci**返回值:** 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci| 类型 | 说明 | 384e41f4b71Sopenharmony_ci| ---------------- | ---------------- | 385e41f4b71Sopenharmony_ci| Promise\<string> | Promise对象,返回当前ability的Bundle名称。 | 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci**示例:** 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 390e41f4b71Sopenharmony_ci```ts 391e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 394e41f4b71Sopenharmony_cicontext.getBundleName().then((data) => { 395e41f4b71Sopenharmony_ci console.info(`getBundleName data: ${JSON.stringify(data)}`); 396e41f4b71Sopenharmony_ci}); 397e41f4b71Sopenharmony_ci``` 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci## Context.getDisplayOrientation<sup>7+</sup> 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_cigetDisplayOrientation(callback: AsyncCallback\<bundle.DisplayOrientation>): void 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci获取当前ability的显示方向。使用callback异步回调。 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ci**参数:** 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 410e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------ | 411e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[bundle.DisplayOrientation](js-apis-bundleManager.md#displayorientation)> | 是 | 回调函数,返回屏幕显示方向。 | 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci**示例:** 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 416e41f4b71Sopenharmony_ci```ts 417e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 420e41f4b71Sopenharmony_cicontext.getDisplayOrientation((error, data) => { 421e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 422e41f4b71Sopenharmony_ci console.error(`getDisplayOrientation fail, error: ${JSON.stringify(error)}`); 423e41f4b71Sopenharmony_ci } else { 424e41f4b71Sopenharmony_ci console.log(`getDisplayOrientation success, data: ${JSON.stringify(data)}`); 425e41f4b71Sopenharmony_ci } 426e41f4b71Sopenharmony_ci}); 427e41f4b71Sopenharmony_ci``` 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci## Context.getDisplayOrientation<sup>7+</sup> 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_cigetDisplayOrientation(): Promise\<bundle.DisplayOrientation> 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci获取此能力的当前显示方向。使用Promise异步回调。 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci**返回值:** 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci| 类型 | 说明 | 440e41f4b71Sopenharmony_ci| ---------------------------------------- | --------- | 441e41f4b71Sopenharmony_ci| Promise\<[bundle.DisplayOrientation](js-apis-bundleManager.md#displayorientation)> | Promise对象,返回屏幕显示方向。 | 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci**示例:** 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 446e41f4b71Sopenharmony_ci```ts 447e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 450e41f4b71Sopenharmony_cicontext.getDisplayOrientation().then((data) => { 451e41f4b71Sopenharmony_ci console.info(`getDisplayOrientation data: ${JSON.stringify(data)}`); 452e41f4b71Sopenharmony_ci}); 453e41f4b71Sopenharmony_ci``` 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci## Context.getExternalCacheDir<sup>(deprecated)</sup> 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_cigetExternalCacheDir(callback: AsyncCallback\<string>): void 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci获取应用程序的外部缓存目录。使用callback异步回调。 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci**说明:** 462e41f4b71Sopenharmony_ci> 463e41f4b71Sopenharmony_ci> 从API version 7开始不再支持。 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ci**参数:** 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 470e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------ | 471e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | 是 | 回调函数,返回应用程序的缓存目录的绝对路径。 | 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**示例:** 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 476e41f4b71Sopenharmony_ci```ts 477e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 480e41f4b71Sopenharmony_cicontext.getExternalCacheDir((error, data) => { 481e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 482e41f4b71Sopenharmony_ci console.error(`getExternalCacheDir fail, error: ${JSON.stringify(error)}`); 483e41f4b71Sopenharmony_ci } else { 484e41f4b71Sopenharmony_ci console.log(`getExternalCacheDir success, data: ${JSON.stringify(data)}`); 485e41f4b71Sopenharmony_ci } 486e41f4b71Sopenharmony_ci}); 487e41f4b71Sopenharmony_ci``` 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci## Context.getExternalCacheDir<sup>(deprecated)</sup> 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_cigetExternalCacheDir(): Promise\<string> 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci获取应用程序的外部缓存目录。使用Promise异步回调。 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ci**说明:** 496e41f4b71Sopenharmony_ci> 497e41f4b71Sopenharmony_ci> 从API version 7开始不再支持。 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci**返回值:** 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci| 类型 | 说明 | 504e41f4b71Sopenharmony_ci| ---------------- | ---------------- | 505e41f4b71Sopenharmony_ci| Promise\<string> | Promise对象,返回应用程序的缓存目录的绝对路径。 | 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci**示例:** 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 510e41f4b71Sopenharmony_ci```ts 511e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 514e41f4b71Sopenharmony_cicontext.getExternalCacheDir().then((data) => { 515e41f4b71Sopenharmony_ci console.info(`getExternalCacheDir data: ${JSON.stringify(data)}`); 516e41f4b71Sopenharmony_ci}); 517e41f4b71Sopenharmony_ci``` 518e41f4b71Sopenharmony_ci 519e41f4b71Sopenharmony_ci## Context.setDisplayOrientation<sup>7+</sup> 520e41f4b71Sopenharmony_ci 521e41f4b71Sopenharmony_cisetDisplayOrientation(orientation: bundle.DisplayOrientation, callback: AsyncCallback\<void>): void 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_ci设置当前Ability的显示方向。使用callback异步回调。 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci**参数:** 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 530e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------ | 531e41f4b71Sopenharmony_ci| orientation | [bundle.DisplayOrientation](js-apis-bundleManager.md#displayorientation) | 是 | 指示当前能力的新方向。 | 532e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | 是 | 回调函数。当设置当前Ability的显示方向成功,err为undefined,否则为错误对象。 | 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci**示例:** 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 537e41f4b71Sopenharmony_ci```ts 538e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 539e41f4b71Sopenharmony_ciimport bundleManager from '@ohos.bundle'; 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 542e41f4b71Sopenharmony_cilet orientation = bundleManager.DisplayOrientation.LANDSCAPE; 543e41f4b71Sopenharmony_cicontext.setDisplayOrientation(orientation, (error) => { 544e41f4b71Sopenharmony_ci console.error(`setDisplayOrientation fail, error: ${JSON.stringify(error)}`); 545e41f4b71Sopenharmony_ci}); 546e41f4b71Sopenharmony_ci``` 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ci## Context.setDisplayOrientation<sup>7+</sup> 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_cisetDisplayOrientation(orientation: bundle.DisplayOrientation): Promise\<void> 551e41f4b71Sopenharmony_ci 552e41f4b71Sopenharmony_ci设置当前Ability的显示方向。使用Promise异步回调。 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 555e41f4b71Sopenharmony_ci 556e41f4b71Sopenharmony_ci**参数:** 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 559e41f4b71Sopenharmony_ci| ---------------------------------------- | ---------------------------------------- | ---- | ------------ | 560e41f4b71Sopenharmony_ci| orientation | [bundle.DisplayOrientation](js-apis-bundleManager.md#displayorientation) | 是 | 表示屏幕显示方向。 | 561e41f4b71Sopenharmony_ci 562e41f4b71Sopenharmony_ci**返回值:** 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci| 类型 | 说明 | 565e41f4b71Sopenharmony_ci| -------------- | ---------------- | 566e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ci**示例:** 569e41f4b71Sopenharmony_ci 570e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 571e41f4b71Sopenharmony_ci```ts 572e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 573e41f4b71Sopenharmony_ciimport bundleManager from '@ohos.bundle'; 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 576e41f4b71Sopenharmony_cilet orientation = bundleManager.DisplayOrientation.UNSPECIFIED; 577e41f4b71Sopenharmony_cicontext.setDisplayOrientation(orientation).then((data) => { 578e41f4b71Sopenharmony_ci console.info(`setDisplayOrientation data: ${JSON.stringify(data)}`); 579e41f4b71Sopenharmony_ci}); 580e41f4b71Sopenharmony_ci``` 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ci## Context.setShowOnLockScreen<sup>(deprecated)</sup> 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_cisetShowOnLockScreen(show: boolean, callback: AsyncCallback\<void>): void 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci设置每当显示锁屏时是否在锁屏顶部显示此功能,使该功能保持激活状态。使用callback异步回调。 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci> **说明:** 589e41f4b71Sopenharmony_ci> 590e41f4b71Sopenharmony_ci> 从API version 9开始不再支持。建议使用window.setShowOnLockScreen替代,新接口为系统接口。 591e41f4b71Sopenharmony_ci 592e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 593e41f4b71Sopenharmony_ci 594e41f4b71Sopenharmony_ci**参数:** 595e41f4b71Sopenharmony_ci 596e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 597e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------- | 598e41f4b71Sopenharmony_ci| show | boolean | 是 | 指定是否在锁屏顶部显示此功能。值true表示在锁屏上显示,值false表示不显示。 | 599e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | 是 | 回调函数。当设置每当显示锁屏时是否在锁屏顶部显示此功能并使该功能保持激活状态的操作成功,err为undefined,否则为错误对象。 | 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_ci**示例:** 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 604e41f4b71Sopenharmony_ci```ts 605e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 608e41f4b71Sopenharmony_cilet show = true; 609e41f4b71Sopenharmony_cicontext.setShowOnLockScreen(show, (error) => { 610e41f4b71Sopenharmony_ci console.error(`setShowOnLockScreen fail, error: ${JSON.stringify(error)}`); 611e41f4b71Sopenharmony_ci}); 612e41f4b71Sopenharmony_ci``` 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci## Context.setShowOnLockScreen<sup>(deprecated)</sup> 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_cisetShowOnLockScreen(show: boolean): Promise\<void> 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci设置每当显示锁屏时是否在锁屏顶部显示此功能,使该功能保持激活状态。使用Promise异步回调。 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ci**说明:** 621e41f4b71Sopenharmony_ci> 622e41f4b71Sopenharmony_ci> 从API version 9开始不再支持。建议使用window.setShowOnLockScreen替代,新接口为系统接口。 623e41f4b71Sopenharmony_ci 624e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 625e41f4b71Sopenharmony_ci 626e41f4b71Sopenharmony_ci**参数:** 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 629e41f4b71Sopenharmony_ci| ---- | ------- | ---- | ---------------------------------------- | 630e41f4b71Sopenharmony_ci| show | boolean | 是 | 指定是否在锁屏顶部显示此功能。值true表示在锁屏上显示,值false表示不显示。 | 631e41f4b71Sopenharmony_ci 632e41f4b71Sopenharmony_ci**返回值:** 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_ci| 类型 | 说明 | 635e41f4b71Sopenharmony_ci| -------------- | --------------- | 636e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci**示例:** 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 641e41f4b71Sopenharmony_ci```ts 642e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 645e41f4b71Sopenharmony_cilet show = true; 646e41f4b71Sopenharmony_cicontext.setShowOnLockScreen(show).then((data) => { 647e41f4b71Sopenharmony_ci console.info(`setShowOnLockScreen data: ${JSON.stringify(data)}`); 648e41f4b71Sopenharmony_ci}); 649e41f4b71Sopenharmony_ci``` 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_ci## Context.setWakeUpScreen<sup>(deprecated)</sup> 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_cisetWakeUpScreen(wakeUp: boolean, callback: AsyncCallback\<void>): void 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci设置恢复此功能时是否唤醒屏幕。使用callback异步回调。 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci**说明:** 658e41f4b71Sopenharmony_ci> 659e41f4b71Sopenharmony_ci> 从API version 7开始支持,从API version 12开始废弃,替代接口window.setWakeUpScreen仅面向系统应用开放。 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ci**参数:** 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 666e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | --------------------------------- | 667e41f4b71Sopenharmony_ci| wakeUp | boolean | 是 | 指定是否唤醒屏幕。值true表示唤醒它,值false表示不唤醒它。 | 668e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | 是 | 回调函数。当设置恢复此功能时是否唤醒屏幕成功,err为undefined,否则为错误对象。 | 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_ci**示例:** 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 673e41f4b71Sopenharmony_ci```ts 674e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 677e41f4b71Sopenharmony_cilet wakeUp = true; 678e41f4b71Sopenharmony_cicontext.setWakeUpScreen(wakeUp, (error) => { 679e41f4b71Sopenharmony_ci console.error(`setWakeUpScreen fail, error: ${JSON.stringify(error)}`); 680e41f4b71Sopenharmony_ci}); 681e41f4b71Sopenharmony_ci``` 682e41f4b71Sopenharmony_ci 683e41f4b71Sopenharmony_ci## Context.setWakeUpScreen<sup>(deprecated)</sup> 684e41f4b71Sopenharmony_ci 685e41f4b71Sopenharmony_cisetWakeUpScreen(wakeUp: boolean): Promise\<void> 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_ci设置恢复此功能时是否唤醒屏幕。使用Promise异步回调。 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_ci**说明:** 690e41f4b71Sopenharmony_ci> 691e41f4b71Sopenharmony_ci> 从API version 7开始支持,从API version 12开始废弃,替代接口window.setWakeUpScreen仅面向系统应用开放。 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci**参数:** 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 698e41f4b71Sopenharmony_ci| ------ | ------- | ---- | --------------------------------- | 699e41f4b71Sopenharmony_ci| wakeUp | boolean | 是 | 指定是否唤醒屏幕。值true表示唤醒它,值false表示不唤醒它。 | 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci**返回值:** 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci| 类型 | 说明 | 704e41f4b71Sopenharmony_ci| -------------- | --------------- | 705e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ci**示例:** 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 710e41f4b71Sopenharmony_ci```ts 711e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 714e41f4b71Sopenharmony_cilet wakeUp = true; 715e41f4b71Sopenharmony_cicontext.setWakeUpScreen(wakeUp).then((data) => { 716e41f4b71Sopenharmony_ci console.info(`setWakeUpScreen data: ${JSON.stringify(data)}`); 717e41f4b71Sopenharmony_ci}); 718e41f4b71Sopenharmony_ci``` 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ci 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci## Context.getProcessInfo<sup>7+</sup> 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_cigetProcessInfo(callback: AsyncCallback\<ProcessInfo>): void 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci获取有关当前进程的信息,包括进程ID和名称。使用callback异步回调。 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_ci**参数:** 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 734e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ---------- | 735e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[ProcessInfo](js-apis-inner-app-processInfo.md)> | 是 | 回调函数,返回当前进程的信息。 | 736e41f4b71Sopenharmony_ci 737e41f4b71Sopenharmony_ci**示例:** 738e41f4b71Sopenharmony_ci 739e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 740e41f4b71Sopenharmony_ci```ts 741e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 744e41f4b71Sopenharmony_cicontext.getProcessInfo((error, data) => { 745e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 746e41f4b71Sopenharmony_ci console.error(`getProcessInfo fail, error: ${JSON.stringify(error)}`); 747e41f4b71Sopenharmony_ci } else { 748e41f4b71Sopenharmony_ci console.log(`getProcessInfo success, data: ${JSON.stringify(data)}`); 749e41f4b71Sopenharmony_ci } 750e41f4b71Sopenharmony_ci}); 751e41f4b71Sopenharmony_ci``` 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci## Context.getProcessInfo<sup>7+</sup> 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_cigetProcessInfo(): Promise\<ProcessInfo> 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci获取有关当前进程的信息,包括进程id和名称。使用Promise异步回调。 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci**返回值:** 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ci| 类型 | 说明 | 766e41f4b71Sopenharmony_ci| --------------------- | ------- | 767e41f4b71Sopenharmony_ci| Promise\<[ProcessInfo](js-apis-inner-app-processInfo.md)> | Promise对象,返回当前进程的信息。 | 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci**示例:** 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 772e41f4b71Sopenharmony_ci```ts 773e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 776e41f4b71Sopenharmony_cicontext.getProcessInfo().then((data) => { 777e41f4b71Sopenharmony_ci console.info(`getProcessInfo data: ${JSON.stringify(data)}`); 778e41f4b71Sopenharmony_ci}); 779e41f4b71Sopenharmony_ci``` 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ci## Context.getElementName<sup>7+</sup> 784e41f4b71Sopenharmony_ci 785e41f4b71Sopenharmony_cigetElementName(callback: AsyncCallback\<ElementName>): void 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci获取当前ability的ohos.bundleManager.ElementName对象。使用callback异步回调。 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_ci此方法仅适用于页面功能。 790e41f4b71Sopenharmony_ci 791e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci**参数:** 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 796e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | -------------------------------------- | 797e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | 回调函数,返回当前ability的ohos.bundleManager.ElementName对象。 | 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci**示例:** 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 802e41f4b71Sopenharmony_ci```ts 803e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 804e41f4b71Sopenharmony_ci 805e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 806e41f4b71Sopenharmony_cicontext.getElementName((error, data) => { 807e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 808e41f4b71Sopenharmony_ci console.error(`getElementName fail, error: ${JSON.stringify(error)}`); 809e41f4b71Sopenharmony_ci } else { 810e41f4b71Sopenharmony_ci console.log(`getElementName success, data: ${JSON.stringify(data)}`); 811e41f4b71Sopenharmony_ci } 812e41f4b71Sopenharmony_ci}); 813e41f4b71Sopenharmony_ci``` 814e41f4b71Sopenharmony_ci 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci## Context.getElementName<sup>7+</sup> 818e41f4b71Sopenharmony_ci 819e41f4b71Sopenharmony_cigetElementName(): Promise\<ElementName> 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci获取当前能力的ohos.bundleManager.ElementName对象。使用Promise异步回调。 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci此方法仅适用于页面功能。 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 826e41f4b71Sopenharmony_ci 827e41f4b71Sopenharmony_ci**返回值:** 828e41f4b71Sopenharmony_ci 829e41f4b71Sopenharmony_ci| 类型 | 说明 | 830e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------ | 831e41f4b71Sopenharmony_ci| Promise\<[ElementName](js-apis-bundleManager-elementName.md)> | Promise对象,返回当前ability的ohos.bundleManager.ElementName对象。 | 832e41f4b71Sopenharmony_ci 833e41f4b71Sopenharmony_ci**示例:** 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 836e41f4b71Sopenharmony_ci```ts 837e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 840e41f4b71Sopenharmony_cicontext.getElementName().then((data) => { 841e41f4b71Sopenharmony_ci console.info(`getElementName data: ${JSON.stringify(data)}`); 842e41f4b71Sopenharmony_ci}); 843e41f4b71Sopenharmony_ci``` 844e41f4b71Sopenharmony_ci 845e41f4b71Sopenharmony_ci## Context.getProcessName<sup>7+</sup> 846e41f4b71Sopenharmony_ci 847e41f4b71Sopenharmony_cigetProcessName(callback: AsyncCallback\<string>): void 848e41f4b71Sopenharmony_ci 849e41f4b71Sopenharmony_ci获取当前进程的名称。使用callback异步回调。 850e41f4b71Sopenharmony_ci 851e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 852e41f4b71Sopenharmony_ci 853e41f4b71Sopenharmony_ci**参数:** 854e41f4b71Sopenharmony_ci 855e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 856e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ---------- | 857e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | 是 | 回调函数,返回当前进程的名称。 | 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ci**示例:** 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 862e41f4b71Sopenharmony_ci```ts 863e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 864e41f4b71Sopenharmony_ci 865e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 866e41f4b71Sopenharmony_cicontext.getProcessName((error, data) => { 867e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 868e41f4b71Sopenharmony_ci console.error(`getProcessName fail, error: ${JSON.stringify(error)}`); 869e41f4b71Sopenharmony_ci } else { 870e41f4b71Sopenharmony_ci console.log(`getProcessName success, data: ${JSON.stringify(data)}`); 871e41f4b71Sopenharmony_ci } 872e41f4b71Sopenharmony_ci}); 873e41f4b71Sopenharmony_ci``` 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ci 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci## Context.getProcessName<sup>7+</sup> 878e41f4b71Sopenharmony_ci 879e41f4b71Sopenharmony_cigetProcessName(): Promise\<string> 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ci获取当前进程的名称。使用Promise异步回调。 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci**返回值:** 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci| 类型 | 说明 | 888e41f4b71Sopenharmony_ci| ---------------- | ---------- | 889e41f4b71Sopenharmony_ci| Promise\<string> | Promise对象,返回当前进程的名称。 | 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci**示例:** 892e41f4b71Sopenharmony_ci 893e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 894e41f4b71Sopenharmony_ci```ts 895e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 896e41f4b71Sopenharmony_ci 897e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 898e41f4b71Sopenharmony_cicontext.getProcessName().then((data) => { 899e41f4b71Sopenharmony_ci console.info(`getProcessName data: ${JSON.stringify(data)}`); 900e41f4b71Sopenharmony_ci}); 901e41f4b71Sopenharmony_ci``` 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci## Context.getCallingBundle<sup>7+</sup> 906e41f4b71Sopenharmony_ci 907e41f4b71Sopenharmony_cigetCallingBundle(callback: AsyncCallback\<string>): void 908e41f4b71Sopenharmony_ci 909e41f4b71Sopenharmony_ci获取ability调用方的Bundle名称。使用callback异步回调。 910e41f4b71Sopenharmony_ci 911e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 912e41f4b71Sopenharmony_ci 913e41f4b71Sopenharmony_ci**参数:** 914e41f4b71Sopenharmony_ci 915e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 916e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ---------------- | 917e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | 是 | 回调函数,返回ability调用方的Bundle名称。 | 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_ci**示例:** 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 922e41f4b71Sopenharmony_ci```ts 923e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 924e41f4b71Sopenharmony_ci 925e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 926e41f4b71Sopenharmony_cicontext.getCallingBundle((error, data) => { 927e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 928e41f4b71Sopenharmony_ci console.error(`getCallingBundle fail, error: ${JSON.stringify(error)}`); 929e41f4b71Sopenharmony_ci } else { 930e41f4b71Sopenharmony_ci console.log(`getCallingBundle success, data: ${JSON.stringify(data)}`); 931e41f4b71Sopenharmony_ci } 932e41f4b71Sopenharmony_ci}); 933e41f4b71Sopenharmony_ci``` 934e41f4b71Sopenharmony_ci 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_ci 937e41f4b71Sopenharmony_ci## Context.getCallingBundle<sup>7+</sup> 938e41f4b71Sopenharmony_ci 939e41f4b71Sopenharmony_cigetCallingBundle(): Promise\<string> 940e41f4b71Sopenharmony_ci 941e41f4b71Sopenharmony_ci获取ability调用方的Bundle名称。使用Promise异步回调。 942e41f4b71Sopenharmony_ci 943e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 944e41f4b71Sopenharmony_ci 945e41f4b71Sopenharmony_ci**返回值:** 946e41f4b71Sopenharmony_ci 947e41f4b71Sopenharmony_ci| 类型 | 说明 | 948e41f4b71Sopenharmony_ci| ---------------- | -------------- | 949e41f4b71Sopenharmony_ci| Promise\<string> | Promise对象,返回ability调用方的Bundle名称。 | 950e41f4b71Sopenharmony_ci 951e41f4b71Sopenharmony_ci**示例:** 952e41f4b71Sopenharmony_ci 953e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 954e41f4b71Sopenharmony_ci```ts 955e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 956e41f4b71Sopenharmony_ci 957e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 958e41f4b71Sopenharmony_cicontext.getCallingBundle().then((data) => { 959e41f4b71Sopenharmony_ci console.info(`getCallingBundle data: ${JSON.stringify(data)}`); 960e41f4b71Sopenharmony_ci}); 961e41f4b71Sopenharmony_ci``` 962e41f4b71Sopenharmony_ci 963e41f4b71Sopenharmony_ci## Context.getCacheDir 964e41f4b71Sopenharmony_ci 965e41f4b71Sopenharmony_cigetCacheDir(callback: AsyncCallback\<string>): void 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ci获取该应用程序的内部存储目录。使用callback异步回调。 968e41f4b71Sopenharmony_ci 969e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 970e41f4b71Sopenharmony_ci 971e41f4b71Sopenharmony_ci**参数:** 972e41f4b71Sopenharmony_ci 973e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 974e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | --------------- | 975e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | 是 | 回调函数,返回该应用程序的内部存储目录。 | 976e41f4b71Sopenharmony_ci 977e41f4b71Sopenharmony_ci**示例:** 978e41f4b71Sopenharmony_ci 979e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 980e41f4b71Sopenharmony_ci```ts 981e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 982e41f4b71Sopenharmony_ci 983e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 984e41f4b71Sopenharmony_cicontext.getCacheDir((error, data) => { 985e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 986e41f4b71Sopenharmony_ci console.error(`getCacheDir fail, error: ${JSON.stringify(error)}`); 987e41f4b71Sopenharmony_ci } else { 988e41f4b71Sopenharmony_ci console.log(`getCacheDir success, data: ${JSON.stringify(data)}`); 989e41f4b71Sopenharmony_ci } 990e41f4b71Sopenharmony_ci}); 991e41f4b71Sopenharmony_ci``` 992e41f4b71Sopenharmony_ci 993e41f4b71Sopenharmony_ci## Context.getCacheDir 994e41f4b71Sopenharmony_ci 995e41f4b71Sopenharmony_cigetCacheDir(): Promise\<string> 996e41f4b71Sopenharmony_ci 997e41f4b71Sopenharmony_ci获取该应用程序的内部存储目录。使用Promise异步回调。 998e41f4b71Sopenharmony_ci 999e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1000e41f4b71Sopenharmony_ci 1001e41f4b71Sopenharmony_ci**返回值:** 1002e41f4b71Sopenharmony_ci 1003e41f4b71Sopenharmony_ci| 类型 | 说明 | 1004e41f4b71Sopenharmony_ci| ---------------- | --------------- | 1005e41f4b71Sopenharmony_ci| Promise\<string> | Promise对象,返回该应用程序的内部存储目录。 | 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_ci**示例:** 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1010e41f4b71Sopenharmony_ci```ts 1011e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1012e41f4b71Sopenharmony_ci 1013e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1014e41f4b71Sopenharmony_cicontext.getCacheDir().then((data) => { 1015e41f4b71Sopenharmony_ci console.info(`getCacheDir data: ${JSON.stringify(data)}`); 1016e41f4b71Sopenharmony_ci}); 1017e41f4b71Sopenharmony_ci``` 1018e41f4b71Sopenharmony_ci 1019e41f4b71Sopenharmony_ci## Context.getFilesDir 1020e41f4b71Sopenharmony_ci 1021e41f4b71Sopenharmony_cigetFilesDir(callback: AsyncCallback\<string>): void 1022e41f4b71Sopenharmony_ci 1023e41f4b71Sopenharmony_ci获取内部存储器上此应用程序的文件目录。使用callback异步回调。 1024e41f4b71Sopenharmony_ci 1025e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1026e41f4b71Sopenharmony_ci 1027e41f4b71Sopenharmony_ci**参数:** 1028e41f4b71Sopenharmony_ci 1029e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1030e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------- | 1031e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | 是 | 回调函数,返回内部存储器上此应用程序的文件目录。 | 1032e41f4b71Sopenharmony_ci 1033e41f4b71Sopenharmony_ci**示例:** 1034e41f4b71Sopenharmony_ci 1035e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1036e41f4b71Sopenharmony_ci```ts 1037e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1038e41f4b71Sopenharmony_ci 1039e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1040e41f4b71Sopenharmony_cicontext.getFilesDir((error, data) => { 1041e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 1042e41f4b71Sopenharmony_ci console.error(`getFilesDir fail, error: ${JSON.stringify(error)}`); 1043e41f4b71Sopenharmony_ci } else { 1044e41f4b71Sopenharmony_ci console.log(`getFilesDir success, data: ${JSON.stringify(data)}`); 1045e41f4b71Sopenharmony_ci } 1046e41f4b71Sopenharmony_ci}); 1047e41f4b71Sopenharmony_ci``` 1048e41f4b71Sopenharmony_ci 1049e41f4b71Sopenharmony_ci## Context.getFilesDir 1050e41f4b71Sopenharmony_ci 1051e41f4b71Sopenharmony_cigetFilesDir(): Promise\<string> 1052e41f4b71Sopenharmony_ci 1053e41f4b71Sopenharmony_ci获取内部存储器上此应用程序的文件目录。使用Promise异步回调。 1054e41f4b71Sopenharmony_ci 1055e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ci**返回值:** 1058e41f4b71Sopenharmony_ci 1059e41f4b71Sopenharmony_ci| 类型 | 说明 | 1060e41f4b71Sopenharmony_ci| ---------------- | ------------------- | 1061e41f4b71Sopenharmony_ci| Promise\<string> | Promise对象,返回内部存储器上此应用程序的文件目录。 | 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_ci**示例:** 1064e41f4b71Sopenharmony_ci 1065e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1066e41f4b71Sopenharmony_ci```ts 1067e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1068e41f4b71Sopenharmony_ci 1069e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1070e41f4b71Sopenharmony_cicontext.getFilesDir().then((data) => { 1071e41f4b71Sopenharmony_ci console.info(`getFilesDir data: ${JSON.stringify(data)}`); 1072e41f4b71Sopenharmony_ci}); 1073e41f4b71Sopenharmony_ci``` 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci## Context.getOrCreateDistributedDir<sup>7+</sup> 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_cigetOrCreateDistributedDir(callback: AsyncCallback\<string>): void 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci获取Ability或应用的分布式文件路径。使用callback异步回调。 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_ci如果分布式文件路径不存在,系统将创建一个路径并返回创建的路径。 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1084e41f4b71Sopenharmony_ci 1085e41f4b71Sopenharmony_ci**参数:** 1086e41f4b71Sopenharmony_ci 1087e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1088e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ---------------------------------------- | 1089e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | 是 | 回调函数,返回Ability或应用的分布式文件路径。<br>若路径不存在,系统将创建一个路径并返回创建的路径。 | 1090e41f4b71Sopenharmony_ci 1091e41f4b71Sopenharmony_ci**示例:** 1092e41f4b71Sopenharmony_ci 1093e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1094e41f4b71Sopenharmony_ci```ts 1095e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1096e41f4b71Sopenharmony_ci 1097e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1098e41f4b71Sopenharmony_cicontext.getOrCreateDistributedDir((error, data) => { 1099e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 1100e41f4b71Sopenharmony_ci console.error(`getOrCreateDistributedDir fail, error: ${JSON.stringify(error)}`); 1101e41f4b71Sopenharmony_ci } else { 1102e41f4b71Sopenharmony_ci console.log(`getOrCreateDistributedDir success, data: ${JSON.stringify(data)}`); 1103e41f4b71Sopenharmony_ci } 1104e41f4b71Sopenharmony_ci}); 1105e41f4b71Sopenharmony_ci``` 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_ci## Context.getOrCreateDistributedDir<sup>7+</sup> 1108e41f4b71Sopenharmony_ci 1109e41f4b71Sopenharmony_cigetOrCreateDistributedDir(): Promise\<string> 1110e41f4b71Sopenharmony_ci 1111e41f4b71Sopenharmony_ci获取Ability或应用的分布式文件路径。使用Promise异步回调。 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci如果分布式文件路径不存在,系统将创建一个路径并返回创建的路径。 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci**返回值:** 1118e41f4b71Sopenharmony_ci 1119e41f4b71Sopenharmony_ci| 类型 | 说明 | 1120e41f4b71Sopenharmony_ci| ---------------- | ----------------------------------- | 1121e41f4b71Sopenharmony_ci| Promise\<string> | Promise对象,返回Ability或应用的分布式文件路径。若为首次调用,则将创建目录。 | 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_ci**示例:** 1124e41f4b71Sopenharmony_ci 1125e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1126e41f4b71Sopenharmony_ci```ts 1127e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1128e41f4b71Sopenharmony_ci 1129e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1130e41f4b71Sopenharmony_cicontext.getOrCreateDistributedDir().then((data) => { 1131e41f4b71Sopenharmony_ci console.info(`getOrCreateDistributedDir data: ${JSON.stringify(data)}`); 1132e41f4b71Sopenharmony_ci}); 1133e41f4b71Sopenharmony_ci``` 1134e41f4b71Sopenharmony_ci 1135e41f4b71Sopenharmony_ci## Context.getAppType<sup>7+</sup> 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_cigetAppType(callback: AsyncCallback\<string>): void 1138e41f4b71Sopenharmony_ci 1139e41f4b71Sopenharmony_ci获取此应用的类型。使用callback异步回调。 1140e41f4b71Sopenharmony_ci 1141e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1142e41f4b71Sopenharmony_ci 1143e41f4b71Sopenharmony_ci**参数:** 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1146e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | -------------------------------- | 1147e41f4b71Sopenharmony_ci| callback | AsyncCallback\<string> | 是 | 回调函数,返回此应用程序的类型。 | 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ci**示例:** 1150e41f4b71Sopenharmony_ci 1151e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1152e41f4b71Sopenharmony_ci```ts 1153e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1156e41f4b71Sopenharmony_cicontext.getAppType((error, data) => { 1157e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 1158e41f4b71Sopenharmony_ci console.error(`getAppType fail, error: ${JSON.stringify(error)}`); 1159e41f4b71Sopenharmony_ci } else { 1160e41f4b71Sopenharmony_ci console.log(`getAppType success, data: ${JSON.stringify(data)}`); 1161e41f4b71Sopenharmony_ci } 1162e41f4b71Sopenharmony_ci}); 1163e41f4b71Sopenharmony_ci``` 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci## Context.getAppType<sup>7+</sup> 1166e41f4b71Sopenharmony_ci 1167e41f4b71Sopenharmony_cigetAppType(): Promise\<string> 1168e41f4b71Sopenharmony_ci 1169e41f4b71Sopenharmony_ci获取此应用的类型。使用Promise异步回调。 1170e41f4b71Sopenharmony_ci 1171e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1172e41f4b71Sopenharmony_ci 1173e41f4b71Sopenharmony_ci**返回值:** 1174e41f4b71Sopenharmony_ci 1175e41f4b71Sopenharmony_ci| 类型 | 说明 | 1176e41f4b71Sopenharmony_ci| ---------------- | ------------------ | 1177e41f4b71Sopenharmony_ci| Promise\<string> | Promise对象,返回此应用的类型。 | 1178e41f4b71Sopenharmony_ci 1179e41f4b71Sopenharmony_ci**示例:** 1180e41f4b71Sopenharmony_ci 1181e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1182e41f4b71Sopenharmony_ci```ts 1183e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1184e41f4b71Sopenharmony_ci 1185e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1186e41f4b71Sopenharmony_cicontext.getAppType().then((data) => { 1187e41f4b71Sopenharmony_ci console.info(`getAppType data: ${JSON.stringify(data)}`); 1188e41f4b71Sopenharmony_ci}); 1189e41f4b71Sopenharmony_ci``` 1190e41f4b71Sopenharmony_ci 1191e41f4b71Sopenharmony_ci## Context.getHapModuleInfo<sup>7+</sup> 1192e41f4b71Sopenharmony_ci 1193e41f4b71Sopenharmony_cigetHapModuleInfo(callback: AsyncCallback\<HapModuleInfo>): void 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ci获取应用的ModuleInfo对象。使用callback异步回调。 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1198e41f4b71Sopenharmony_ci 1199e41f4b71Sopenharmony_ci**参数:** 1200e41f4b71Sopenharmony_ci 1201e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1202e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------------------------------------- | 1203e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[HapModuleInfo](js-apis-bundleManager-hapModuleInfo.md)> | 是 | 回调函数,返回应用的ModuleInfo对象。 | 1204e41f4b71Sopenharmony_ci 1205e41f4b71Sopenharmony_ci**示例:** 1206e41f4b71Sopenharmony_ci 1207e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1208e41f4b71Sopenharmony_ci```ts 1209e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1210e41f4b71Sopenharmony_ci 1211e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1212e41f4b71Sopenharmony_cicontext.getHapModuleInfo((error, data) => { 1213e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 1214e41f4b71Sopenharmony_ci console.error(`getHapModuleInfo fail, error: ${JSON.stringify(error)}`); 1215e41f4b71Sopenharmony_ci } else { 1216e41f4b71Sopenharmony_ci console.log(`getHapModuleInfo success, data: ${JSON.stringify(data)}`); 1217e41f4b71Sopenharmony_ci } 1218e41f4b71Sopenharmony_ci}); 1219e41f4b71Sopenharmony_ci``` 1220e41f4b71Sopenharmony_ci 1221e41f4b71Sopenharmony_ci## Context.getHapModuleInfo<sup>7+</sup> 1222e41f4b71Sopenharmony_ci 1223e41f4b71Sopenharmony_cigetHapModuleInfo(): Promise\<HapModuleInfo> 1224e41f4b71Sopenharmony_ci 1225e41f4b71Sopenharmony_ci获取应用的ModuleInfo对象。使用Promise异步回调。 1226e41f4b71Sopenharmony_ci 1227e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1228e41f4b71Sopenharmony_ci 1229e41f4b71Sopenharmony_ci**返回值:** 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ci| 类型 | 说明 | 1232e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------------ | 1233e41f4b71Sopenharmony_ci| Promise\<[HapModuleInfo](js-apis-bundleManager-hapModuleInfo.md)> | Promise对象,返回应用的ModuleInfo对象。 | 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ci**示例:** 1236e41f4b71Sopenharmony_ci 1237e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1238e41f4b71Sopenharmony_ci```ts 1239e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1240e41f4b71Sopenharmony_ci 1241e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1242e41f4b71Sopenharmony_cicontext.getHapModuleInfo().then((data) => { 1243e41f4b71Sopenharmony_ci console.info(`getHapModuleInfo data: ${JSON.stringify(data)}`); 1244e41f4b71Sopenharmony_ci}); 1245e41f4b71Sopenharmony_ci``` 1246e41f4b71Sopenharmony_ci 1247e41f4b71Sopenharmony_ci## Context.getAppVersionInfo<sup>7+</sup> 1248e41f4b71Sopenharmony_ci 1249e41f4b71Sopenharmony_cigetAppVersionInfo(callback: AsyncCallback\<AppVersionInfo>): void 1250e41f4b71Sopenharmony_ci 1251e41f4b71Sopenharmony_ci获取应用的版本信息。使用callback异步回调。 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1254e41f4b71Sopenharmony_ci 1255e41f4b71Sopenharmony_ci**参数:** 1256e41f4b71Sopenharmony_ci 1257e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1258e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------ | 1259e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[AppVersionInfo](js-apis-inner-app-appVersionInfo.md)> | 是 | 回调函数,返回应用版本信息。 | 1260e41f4b71Sopenharmony_ci 1261e41f4b71Sopenharmony_ci**示例:** 1262e41f4b71Sopenharmony_ci 1263e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1264e41f4b71Sopenharmony_ci```ts 1265e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1266e41f4b71Sopenharmony_ci 1267e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1268e41f4b71Sopenharmony_cicontext.getAppVersionInfo((error, data) => { 1269e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 1270e41f4b71Sopenharmony_ci console.error(`getAppVersionInfo fail, error: ${JSON.stringify(error)}`); 1271e41f4b71Sopenharmony_ci } else { 1272e41f4b71Sopenharmony_ci console.log(`getAppVersionInfo success, data: ${JSON.stringify(data)}`); 1273e41f4b71Sopenharmony_ci } 1274e41f4b71Sopenharmony_ci}); 1275e41f4b71Sopenharmony_ci``` 1276e41f4b71Sopenharmony_ci 1277e41f4b71Sopenharmony_ci## Context.getAppVersionInfo<sup>7+</sup> 1278e41f4b71Sopenharmony_ci 1279e41f4b71Sopenharmony_cigetAppVersionInfo(): Promise\<AppVersionInfo> 1280e41f4b71Sopenharmony_ci 1281e41f4b71Sopenharmony_ci获取应用的版本信息。使用Promise异步回调。 1282e41f4b71Sopenharmony_ci 1283e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1284e41f4b71Sopenharmony_ci 1285e41f4b71Sopenharmony_ci**返回值:** 1286e41f4b71Sopenharmony_ci 1287e41f4b71Sopenharmony_ci| 类型 | 说明 | 1288e41f4b71Sopenharmony_ci| ---------------------------------------- | --------- | 1289e41f4b71Sopenharmony_ci| Promise\<[AppVersionInfo](js-apis-inner-app-appVersionInfo.md)> | Promise对象,返回应用版本信息。 | 1290e41f4b71Sopenharmony_ci 1291e41f4b71Sopenharmony_ci**示例:** 1292e41f4b71Sopenharmony_ci 1293e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1294e41f4b71Sopenharmony_ci```ts 1295e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1296e41f4b71Sopenharmony_ci 1297e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1298e41f4b71Sopenharmony_cicontext.getAppVersionInfo().then((data) => { 1299e41f4b71Sopenharmony_ci console.info(`getAppVersionInfo data: ${JSON.stringify(data)}`); 1300e41f4b71Sopenharmony_ci}); 1301e41f4b71Sopenharmony_ci``` 1302e41f4b71Sopenharmony_ci 1303e41f4b71Sopenharmony_ci## Context.getAbilityInfo<sup>7+</sup> 1304e41f4b71Sopenharmony_ci 1305e41f4b71Sopenharmony_cigetAbilityInfo(callback: AsyncCallback\<AbilityInfo>): void 1306e41f4b71Sopenharmony_ci 1307e41f4b71Sopenharmony_ci查询当前归属Ability详细信息。使用callback异步回调。 1308e41f4b71Sopenharmony_ci 1309e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1310e41f4b71Sopenharmony_ci 1311e41f4b71Sopenharmony_ci**参数:** 1312e41f4b71Sopenharmony_ci 1313e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1314e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------------------------------------- | 1315e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)> | 是 | 回调函数,返回当前归属Ability详细信息。 | 1316e41f4b71Sopenharmony_ci 1317e41f4b71Sopenharmony_ci**示例:** 1318e41f4b71Sopenharmony_ci 1319e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1320e41f4b71Sopenharmony_ci```ts 1321e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1322e41f4b71Sopenharmony_ci 1323e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1324e41f4b71Sopenharmony_cicontext.getAbilityInfo((error, data) => { 1325e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 1326e41f4b71Sopenharmony_ci console.error(`getAbilityInfo fail, error: ${JSON.stringify(error)}`); 1327e41f4b71Sopenharmony_ci } else { 1328e41f4b71Sopenharmony_ci console.log(`getAbilityInfo success, data: ${JSON.stringify(data)}`); 1329e41f4b71Sopenharmony_ci } 1330e41f4b71Sopenharmony_ci}); 1331e41f4b71Sopenharmony_ci``` 1332e41f4b71Sopenharmony_ci 1333e41f4b71Sopenharmony_ci## Context.getAbilityInfo<sup>7+</sup> 1334e41f4b71Sopenharmony_ci 1335e41f4b71Sopenharmony_cigetAbilityInfo(): Promise\<AbilityInfo> 1336e41f4b71Sopenharmony_ci 1337e41f4b71Sopenharmony_ci查询当前归属Ability详细信息。使用Promise异步回调。 1338e41f4b71Sopenharmony_ci 1339e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1340e41f4b71Sopenharmony_ci 1341e41f4b71Sopenharmony_ci**返回值:** 1342e41f4b71Sopenharmony_ci 1343e41f4b71Sopenharmony_ci| 类型 | 说明 | 1344e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------------ | 1345e41f4b71Sopenharmony_ci| Promise\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)> | Promise对象,返回当前归属Ability详细信息。 | 1346e41f4b71Sopenharmony_ci 1347e41f4b71Sopenharmony_ci**示例:** 1348e41f4b71Sopenharmony_ci 1349e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1350e41f4b71Sopenharmony_ci```ts 1351e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1352e41f4b71Sopenharmony_ci 1353e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1354e41f4b71Sopenharmony_cicontext.getAbilityInfo().then((data) => { 1355e41f4b71Sopenharmony_ci console.info(`getAbilityInfo data: ${JSON.stringify(data)}`); 1356e41f4b71Sopenharmony_ci}); 1357e41f4b71Sopenharmony_ci``` 1358e41f4b71Sopenharmony_ci 1359e41f4b71Sopenharmony_ci## Context.getApplicationContext<sup>7+</sup> 1360e41f4b71Sopenharmony_ci 1361e41f4b71Sopenharmony_cigetApplicationContext(): Context 1362e41f4b71Sopenharmony_ci 1363e41f4b71Sopenharmony_ci获取应用上下文信息。 1364e41f4b71Sopenharmony_ci 1365e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1366e41f4b71Sopenharmony_ci 1367e41f4b71Sopenharmony_ci**返回值:** 1368e41f4b71Sopenharmony_ci 1369e41f4b71Sopenharmony_ci| 类型 | 说明 | 1370e41f4b71Sopenharmony_ci| ------- | ---------- | 1371e41f4b71Sopenharmony_ci| Context | 返回应用上下文信息。 | 1372e41f4b71Sopenharmony_ci 1373e41f4b71Sopenharmony_ci**示例:** 1374e41f4b71Sopenharmony_ci 1375e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1376e41f4b71Sopenharmony_ci```ts 1377e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1378e41f4b71Sopenharmony_ci 1379e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext().getApplicationContext(); 1380e41f4b71Sopenharmony_ci``` 1381e41f4b71Sopenharmony_ci 1382e41f4b71Sopenharmony_ci## Context.isUpdatingConfigurations<sup>7+</sup> 1383e41f4b71Sopenharmony_ci 1384e41f4b71Sopenharmony_ciisUpdatingConfigurations(callback: AsyncCallback\<boolean>): void 1385e41f4b71Sopenharmony_ci 1386e41f4b71Sopenharmony_ci检查此能力的配置是否正在更改。使用callback异步回调。 1387e41f4b71Sopenharmony_ci 1388e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1389e41f4b71Sopenharmony_ci 1390e41f4b71Sopenharmony_ci**参数:** 1391e41f4b71Sopenharmony_ci 1392e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1393e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ----------------------------- | 1394e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示该Ability的配置正在更改,否则返回false。 | 1395e41f4b71Sopenharmony_ci 1396e41f4b71Sopenharmony_ci**示例:** 1397e41f4b71Sopenharmony_ci 1398e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1399e41f4b71Sopenharmony_ci```ts 1400e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1401e41f4b71Sopenharmony_ci 1402e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1403e41f4b71Sopenharmony_cicontext.isUpdatingConfigurations((error, data) => { 1404e41f4b71Sopenharmony_ci if (error && error.code !== 0) { 1405e41f4b71Sopenharmony_ci console.error(`isUpdatingConfigurations fail, error: ${JSON.stringify(error)}`); 1406e41f4b71Sopenharmony_ci } else { 1407e41f4b71Sopenharmony_ci console.log(`isUpdatingConfigurations success, data: ${JSON.stringify(data)}`); 1408e41f4b71Sopenharmony_ci } 1409e41f4b71Sopenharmony_ci}); 1410e41f4b71Sopenharmony_ci``` 1411e41f4b71Sopenharmony_ci 1412e41f4b71Sopenharmony_ci## Context.isUpdatingConfigurations<sup>7+</sup> 1413e41f4b71Sopenharmony_ci 1414e41f4b71Sopenharmony_ciisUpdatingConfigurations(): Promise\<boolean> 1415e41f4b71Sopenharmony_ci 1416e41f4b71Sopenharmony_ci检查此能力的配置是否正在更改。使用Promise异步回调。 1417e41f4b71Sopenharmony_ci 1418e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1419e41f4b71Sopenharmony_ci 1420e41f4b71Sopenharmony_ci**返回值:** 1421e41f4b71Sopenharmony_ci 1422e41f4b71Sopenharmony_ci| 类型 | 说明 | 1423e41f4b71Sopenharmony_ci| ----------------- | ----------------------------- | 1424e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise对象,返回true表示该Ability的配置正在更改,否则返回false。 | 1425e41f4b71Sopenharmony_ci 1426e41f4b71Sopenharmony_ci**示例:** 1427e41f4b71Sopenharmony_ci 1428e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1429e41f4b71Sopenharmony_ci```ts 1430e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1431e41f4b71Sopenharmony_ci 1432e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1433e41f4b71Sopenharmony_cicontext.isUpdatingConfigurations().then((data) => { 1434e41f4b71Sopenharmony_ci console.info(`isUpdatingConfigurations data: ${JSON.stringify(data)}`); 1435e41f4b71Sopenharmony_ci}); 1436e41f4b71Sopenharmony_ci``` 1437e41f4b71Sopenharmony_ci 1438e41f4b71Sopenharmony_ci## Context.printDrawnCompleted<sup>7+</sup> 1439e41f4b71Sopenharmony_ci 1440e41f4b71Sopenharmony_ciprintDrawnCompleted(callback: AsyncCallback\<void>): void 1441e41f4b71Sopenharmony_ci 1442e41f4b71Sopenharmony_ci通知系统绘制此页面功能所需的时间。使用callback异步回调。 1443e41f4b71Sopenharmony_ci 1444e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1445e41f4b71Sopenharmony_ci 1446e41f4b71Sopenharmony_ci**参数:** 1447e41f4b71Sopenharmony_ci 1448e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1449e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ----------- | 1450e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | 是 | 回调函数。当通知系统绘制此页面功能所需的时间成功,err为undefined,否则为错误对象。 | 1451e41f4b71Sopenharmony_ci 1452e41f4b71Sopenharmony_ci**示例:** 1453e41f4b71Sopenharmony_ci 1454e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1455e41f4b71Sopenharmony_ci```ts 1456e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1457e41f4b71Sopenharmony_ci 1458e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1459e41f4b71Sopenharmony_cicontext.printDrawnCompleted((err) => { 1460e41f4b71Sopenharmony_ci console.error(`printDrawnCompleted err: ${JSON.stringify(err)}`); 1461e41f4b71Sopenharmony_ci}); 1462e41f4b71Sopenharmony_ci``` 1463e41f4b71Sopenharmony_ci 1464e41f4b71Sopenharmony_ci## Context.printDrawnCompleted<sup>7+</sup> 1465e41f4b71Sopenharmony_ci 1466e41f4b71Sopenharmony_ciprintDrawnCompleted(): Promise\<void> 1467e41f4b71Sopenharmony_ci 1468e41f4b71Sopenharmony_ci通知系统绘制此页面功能所需的时间。使用Promise异步回调。 1469e41f4b71Sopenharmony_ci 1470e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 1471e41f4b71Sopenharmony_ci 1472e41f4b71Sopenharmony_ci**返回值:** 1473e41f4b71Sopenharmony_ci 1474e41f4b71Sopenharmony_ci| 类型 | 说明 | 1475e41f4b71Sopenharmony_ci| -------------- | --------------- | 1476e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 1477e41f4b71Sopenharmony_ci 1478e41f4b71Sopenharmony_ci**示例:** 1479e41f4b71Sopenharmony_ci 1480e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 1481e41f4b71Sopenharmony_ci```ts 1482e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 1483e41f4b71Sopenharmony_ci 1484e41f4b71Sopenharmony_cilet context: featureAbility.Context = featureAbility.getContext(); 1485e41f4b71Sopenharmony_cicontext.printDrawnCompleted().then((data) => { 1486e41f4b71Sopenharmony_ci console.info(`printDrawnCompleted data: ${JSON.stringify(data)}`); 1487e41f4b71Sopenharmony_ci}); 1488e41f4b71Sopenharmony_ci``` 1489e41f4b71Sopenharmony_ci 1490e41f4b71Sopenharmony_ci 1491e41f4b71Sopenharmony_ci## PermissionOptions<sup>7+</sup> 1492e41f4b71Sopenharmony_ci 1493e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core 1494e41f4b71Sopenharmony_ci 1495e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1496e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----- | 1497e41f4b71Sopenharmony_ci| pid |number | 否 | 进程id。 | 1498e41f4b71Sopenharmony_ci| uid |number | 否 | 用户id。 | 1499e41f4b71Sopenharmony_ci 1500e41f4b71Sopenharmony_ci## PermissionRequestResult<sup>7+</sup> 1501e41f4b71Sopenharmony_ci 1502e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core 1503e41f4b71Sopenharmony_ci 1504e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1505e41f4b71Sopenharmony_ci| ----------- |-------------- | ---- | ---------- | 1506e41f4b71Sopenharmony_ci| requestCode | number | 是 | 用户传入的请求代码。 | 1507e41f4b71Sopenharmony_ci| permissions | Array\<string> | 是 | 用户传入的权限。 | 1508e41f4b71Sopenharmony_ci| authResults | Array\<number> | 是 | 请求权限的结果。 |