• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Context (FA Model)
2
3
4There is only one context in the FA model. All capabilities in the context are provided through methods. The context uses these methods to extend the capabilities of the **featureAbility** class.
5
6
7## Available APIs
8
9To use the context in the FA model, first import the **featureAbility** module.
10
11
12```ts
13import featureAbility from "@ohos.ability.featureAbility";
14```
15
16Then, call **getContext()** to obtain the **Context** object:
17
18
19```ts
20let context = featureAbility.getContext()
21```
22
23For details about the APIs, see [API Reference](../reference/apis/js-apis-inner-app-context.md).
24
25
26## How to Develop
27
281. Query bundle information.
29
30   ```ts
31   import featureAbility from '@ohos.ability.featureAbility'
32   export default {
33     onCreate() {
34       // Obtain the context and call related APIs.
35       let context = featureAbility.getContext();
36       context.getBundleName((data, bundleName)=>{
37         console.info("ability bundleName:" + bundleName)
38       });
39       console.info('Application onCreate')
40     },
41     onDestroy() {
42       console.info('Application onDestroy')
43     },
44   }
45   ```
46
472. Set the display orientation of the host featureAbility.
48
49   ```ts
50   import featureAbility from '@ohos.ability.featureAbility'
51   import bundle from '@ohos.bundle';
52
53   export default {
54     onCreate() {
55       // Obtain the context and call related APIs.
56       let context = featureAbility.getContext();
57       context.setDisplayOrientation(bundle.DisplayOrientation.LANDSCAPE).then(() => {
58           console.info("Set display orientation.")
59       })
60       console.info('Application onCreate')
61     },
62     onDestroy() {
63       console.info('Application onDestroy')
64     },
65   }
66   ```
67