harmony 鸿蒙Context (FA Model)
Context (FA Model)
There 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.
Available APIs
To use the context in the FA model, first import the featureAbility module.
import featureAbility from "@ohos.ability.featureAbility";
Then, call getContext() to obtain the Context object:
import featureAbility from "@ohos.ability.featureAbility";
let context = featureAbility.getContext()
For details about the APIs, see API Reference.
How to Develop
- Query bundle information.
import featureAbility from '@ohos.ability.featureAbility'
class Entry {
onCreate() {
// Obtain the context and call related APIs.
let context = featureAbility.getContext();
context.getBundleName((data, bundleName)=>{
console.info("ability bundleName:" + bundleName)
});
console.info('Application onCreate')
}
onDestroy() {
console.info('Application onDestroy')
}
}
export default new Entry()
- Set the display orientation of the featureAbility.
import featureAbility from '@ohos.ability.featureAbility'
import bundleManager from '@ohos.bundle.bundleManager';
class Entry {
onCreate() {
// Obtain the context and call related APIs.
let context = featureAbility.getContext();
context.setDisplayOrientation(bundleManager.DisplayOrientation.LANDSCAPE).then(() => {
console.info("Set display orientation.")
})
console.info('Application onCreate')
}
onDestroy() {
console.info('Application onDestroy')
}
}
export default new Entry();
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Using Explicit Want to Start an Application Component
harmony 鸿蒙Using Implicit Want to Open a Website
harmony 鸿蒙AbilityStage Component Container
harmony 鸿蒙Accessing a DataAbility
harmony 鸿蒙Accessing a DataShareExtensionAbility from the FA Model
harmony 鸿蒙AccessibilityExtensionAbility
harmony 鸿蒙Common action and entities Values
0
赞
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦