• 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
20import featureAbility from "@ohos.ability.featureAbility";
21
22let context = featureAbility.getContext()
23```
24
25For details about the APIs, see [API Reference](../reference/apis/js-apis-inner-app-context.md).
26
27
28## How to Develop
29
301. Query bundle information.
31
32   ```ts
33    import featureAbility from '@ohos.ability.featureAbility'
34
35    class Entry {
36      onCreate() {
37        // Obtain the context and call related APIs.
38        let context = featureAbility.getContext();
39        context.getBundleName((data, bundleName)=>{
40          console.info("ability bundleName:" + bundleName)
41        });
42        console.info('Application onCreate')
43      }
44      onDestroy() {
45        console.info('Application onDestroy')
46      }
47    }
48
49    export default new Entry()
50   ```
51
522. Set the display orientation of the **featureAbility**.
53
54   ```ts
55    import featureAbility from '@ohos.ability.featureAbility'
56    import bundleManager from '@ohos.bundle.bundleManager';
57
58    class Entry {
59      onCreate() {
60        // Obtain the context and call related APIs.
61        let context = featureAbility.getContext();
62        context.setDisplayOrientation(bundleManager.DisplayOrientation.LANDSCAPE).then(() => {
63          console.info("Set display orientation.")
64        })
65        console.info('Application onCreate')
66      }
67      onDestroy() {
68        console.info('Application onDestroy')
69      }
70    }
71
72    export default new Entry();
73   ```
74