提交 d0ed4f4a 编写于 作者: D dy_study

IssueNo:#I5QUG1

Description:FeatureAbility和Context接口示例问题修改
Sig:SIG_ApplicationFramework
Feature or Bugfix:Bugfix
Binary Source: No
Signed-off-by: Ndy_study <dingyao5@huawei.com>
Change-Id: I36cd823010c189dfc2b4b7b63dfdb3327ef1cf46
上级 ce4cfced
......@@ -94,13 +94,13 @@ export default {
**示例**
```javascript
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
var lifecycleid;
export default class MyAbilityStage extends AbilityStage {
export default class MainAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MainAbility onCreate")
let AbilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
......@@ -139,11 +139,11 @@ export default class MyAbilityStage extends AbilityStage {
// 2.通过applicationContext注册监听应用内生命周期
lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
}
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.unregisterAbilityLifecycleCallback(lifecycleid, (error, data) => {
console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
});
}
}
......
......@@ -176,7 +176,7 @@ let promise = featureAbility.startAbility(
```javascript
import featureAbility from '@ohos.ability.featureAbility';
let connId = featureAbility.connectAbility(
let connectId = featureAbility.connectAbility(
{
bundleName: "com.jstest.service",
abilityName: "com.jstest.service.ServiceAbility",
......@@ -293,7 +293,7 @@ function getRemoteDeviceId() {
```ts
import featureAbility from '@ohos.ability.featureAbility';
let connId = featureAbility.connectAbility(
let connectId = featureAbility.connectAbility(
{
deviceId: getRemoteDeviceId(),
bundleName: "ohos.samples.etsDemo",
......
......@@ -12,9 +12,11 @@ Context模块提供了ability或application的上下文的能力,包括允许
Context对象是在featureAbility中创建实例,并通过featureAbility的getContext()接口返回,因此在使用Context时,必须导入@ohos.ability.featureAbility库。示例如下:
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getOrCreateLocalDir()
context.getOrCreateLocalDir().then((data) => {
console.info("getOrCreateLocalDir data: " + JSON.stringify(data));
});
```
## Context.getOrCreateLocalDir<sup>7+</sup>
......@@ -36,11 +38,11 @@ getOrCreateLocalDir(callback: AsyncCallback\<string>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getOrCreateLocalDir((err, data)=>{
console.info("data=" + data);
})
console.info("getOrCreateLocalDir err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -64,10 +66,10 @@ getOrCreateLocalDir(): Promise\<string>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getOrCreateLocalDir().then((data) => {
console.info("data=" + data);
console.info("getOrCreateLocalDir data: " + JSON.stringify(data));
});
```
......@@ -92,11 +94,13 @@ verifyPermission(permission: string, options: PermissionOptions, callback: Async
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility';
import bundle from '@ohos.bundle';
var context = featureAbility.getContext();
bundle.getBundleInfo('com.context.test', 1, (err,datainfo) =>{
context.verifyPermission("com.example.permission", {uid:datainfo.uid});
bundle.getBundleInfo('com.context.test', 1, (err, datainfo) =>{
context.verifyPermission("com.example.permission", {uid:datainfo.uid}, (err, data) =>{
console.info("verifyPermission err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
});
```
......@@ -120,9 +124,11 @@ verifyPermission(permission: string, callback: AsyncCallback\<number>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.verifyPermission("com.example.permission")
context.verifyPermission("com.example.permission", (err, data) =>{
console.info("verifyPermission err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
## Context.verifyPermission<sup>7+</sup>
......@@ -149,12 +155,11 @@ verifyPermission(permission: string, options?: PermissionOptions): Promise\<numb
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
var Permission = {pid:1};
context.verifyPermission('com.context.permission',Permission).then((data) => {
console.info("======================>verifyPermissionCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("verifyPermission data: " + JSON.stringify(data));
});
```
......@@ -179,7 +184,7 @@ requestPermissionsFromUser(permissions: Array\<string>, requestCode: number, res
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.requestPermissionsFromUser(
["com.example.permission1",
......@@ -187,11 +192,11 @@ context.requestPermissionsFromUser(
"com.example.permission3",
"com.example.permission4",
"com.example.permission5"],
1,(err, data)=>{
console.info("====>requestdata====>" + JSON.stringify(data));
console.info("====>requesterrcode====>" + JSON.stringify(err.code));
1,
(err, data) => {
console.info("requestPermissionsFromUser err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
}
)
);
```
......@@ -219,7 +224,7 @@ requestPermissionsFromUser(permissions: Array\<string>, requestCode: number): Pr
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.requestPermissionsFromUser(
["com.example.permission1",
......@@ -228,8 +233,9 @@ context.requestPermissionsFromUser(
"com.example.permission4",
"com.example.permission5"],
1).then((data)=>{
console.info("====>requestdata====>" + JSON.stringify(data));
});
console.info("requestPermissionsFromUser data: " + JSON.stringify(data));
}
);
```
......@@ -251,9 +257,11 @@ getApplicationInfo(callback: AsyncCallback\<ApplicationInfo>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getApplicationInfo()
context.getApplicationInfo((err, data) => {
console.info("getApplicationInfo err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -275,11 +283,10 @@ getApplicationInfo(): Promise\<ApplicationInfo>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getApplicationInfo().then((data) => {
console.info("=====================>getApplicationInfoCallback===================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getApplicationInfo data: " + JSON.stringify(data));
});
```
......@@ -302,9 +309,11 @@ getBundleName(callback: AsyncCallback\<string>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getBundleName()
context.getBundleName((err, data) => {
console.info("getBundleName err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -326,11 +335,10 @@ getBundleName(): Promise\<string>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getBundleName().then((data) => {
console.info("=======================>getBundleNameCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getBundleName data: " + JSON.stringify(data));
});
```
......@@ -351,9 +359,11 @@ getDisplayOrientation(callback: AsyncCallback\<bundle.DisplayOrientation>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getDisplayOrientation()
context.getDisplayOrientation((err, data) => {
console.info("getDisplayOrientation err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
## Context.getDisplayOrientation<sup>7+</sup>
......@@ -373,11 +383,10 @@ getDisplayOrientation(): Promise\<bundle.DisplayOrientation>;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getDisplayOrientation().then((data) => {
console.info("=======================>getDisplayOrientationCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getDisplayOrientation data: " + JSON.stringify(data));
});
```
......@@ -398,9 +407,11 @@ getExternalCacheDir(callback: AsyncCallback\<string>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getExternalCacheDir()
context.getExternalCacheDir((err, data) => {
console.info("getExternalCacheDir err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
## Context.getExternalCacheDir
......@@ -420,11 +431,10 @@ getExternalCacheDir(): Promise\<string>;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getExternalCacheDir().then((data) => {
console.info("=======================>getExternalCacheDirCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getExternalCacheDir data: " + JSON.stringify(data));
});
```
......@@ -446,12 +456,12 @@ setDisplayOrientation(orientation: bundle.DisplayOrientation, callback: AsyncCal
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility';
import bundle from '@ohos.bundle';
var context = featureAbility.getContext();
var orientation=bundle.DisplayOrientation.UNSPECIFIED
context.setDisplayOrientation(orientation, (err) => {
console.log('---------- setDisplayOrientation fail, err: -----------', err);
context.setDisplayOrientation(orientation, (err, data) => {
console.info("setDisplayOrientation err: " + JSON.stringify(err));
});
```
......@@ -473,13 +483,12 @@ setDisplayOrientation(orientation: bundle.DisplayOrientation): Promise\<void>;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility';
import bundle from '@ohos.bundle';
var context = featureAbility.getContext();
var orientation=bundle.DisplayOrientation.UNSPECIFIED
context.setDisplayOrientation(orientation).then((data) => {
console.info("=======================>setDisplayOrientationCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("setDisplayOrientation data: " + JSON.stringify(data));
});
```
......@@ -501,11 +510,11 @@ setShowOnLockScreen(show: boolean, callback: AsyncCallback\<void>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
var show=true
context.setShowOnLockScreen(show, (err) => {
console.log('---------- setShowOnLockScreen fail, err: -----------', err);
context.setShowOnLockScreen(show, (err, data) => {
console.info("setShowOnLockScreen err: " + JSON.stringify(err));
});
```
......@@ -532,12 +541,11 @@ setShowOnLockScreen(show: boolean): Promise\<void>;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
var show=true
context.setShowOnLockScreen(show).then((data) => {
console.info("=======================>setShowOnLockScreenCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("setShowOnLockScreen data: " + JSON.stringify(data));
});
```
......@@ -559,11 +567,11 @@ setWakeUpScreen(wakeUp: boolean, callback: AsyncCallback\<void>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
var wakeUp=true
context.setWakeUpScreen(wakeUp, (err) => {
console.log('---------- setWakeUpScreen fail, err: -----------', err);
context.setWakeUpScreen(wakeUp, (err, data) => {
console.info("setWakeUpScreen err: " + JSON.stringify(err));
});
```
......@@ -590,12 +598,11 @@ setWakeUpScreen(wakeUp: boolean): Promise\<void>;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
var wakeUp=true
context.setWakeUpScreen(wakeUp).then((data) => {
console.info("=======================>setWakeUpScreenCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("setWakeUpScreen data: " + JSON.stringify(data));
});
```
......@@ -619,9 +626,11 @@ getProcessInfo(callback: AsyncCallback\<ProcessInfo>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getProcessInfo()
context.getProcessInfo((err, data) => {
console.info("getProcessInfo err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -643,11 +652,10 @@ getProcessInfo(): Promise\<ProcessInfo>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getProcessInfo().then((data) => {
console.info("=======================>getProcessInfoCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getProcessInfo data: " + JSON.stringify(data));
});
```
......@@ -672,9 +680,11 @@ getElementName(callback: AsyncCallback\<ElementName>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getElementName()
context.getElementName((err, data) => {
console.info("getElementName err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -698,11 +708,10 @@ getElementName(): Promise\<ElementName>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getElementName().then((data) => {
console.info("=======================>getElementNameCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getElementName data: " + JSON.stringify(data));
});
```
......@@ -723,9 +732,11 @@ getProcessName(callback: AsyncCallback\<string>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getProcessName()
context.getProcessName((err, data) => {
console.info("getProcessName err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -747,11 +758,10 @@ getProcessName(): Promise\<string>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getProcessName().then((data) => {
console.info("=======================>getProcessNameCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getProcessName data: " + JSON.stringify(data));
});
```
......@@ -774,9 +784,11 @@ getCallingBundle(callback: AsyncCallback\<string>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getCallingBundle()
context.getCallingBundle((err, data) => {
console.info("getCallingBundle err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -798,11 +810,10 @@ getCallingBundle(): Promise\<string>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getCallingBundle().then((data) => {
console.info("======================>getCallingBundleCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getCallingBundle data: " + JSON.stringify(data));
});
```
......@@ -823,14 +834,10 @@ getCacheDir(callback: AsyncCallback\<string>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getCacheDir((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
console.info("getCacheDir err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -851,11 +858,10 @@ getCacheDir(): Promise\<string>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getCacheDir().then((data) => {
console.info("======================>getCacheDirPromsie====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getCacheDir data: " + JSON.stringify(data));
});
```
......@@ -876,14 +882,10 @@ getFilesDir(callback: AsyncCallback\<string>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getFilesDir((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
console.info("getFilesDir err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -904,11 +906,10 @@ getFilesDir(): Promise\<string>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getFilesDir().then((data) => {
console.info("======================>getFilesDirPromsie====================>");
console.info("====>data====>" + JSON.stringify(data));
console.info("getFilesDir data: " + JSON.stringify(data));
});
```
......@@ -931,14 +932,10 @@ getOrCreateDistributedDir(callback: AsyncCallback\<string>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getOrCreateDistributedDir((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
console.info("getOrCreateDistributedDir err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -961,10 +958,10 @@ getOrCreateDistributedDir(): Promise\<string>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getOrCreateDistributedDir().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
console.info("getOrCreateDistributedDir data: " + JSON.stringify(data));
});
```
......@@ -985,14 +982,10 @@ getAppType(callback: AsyncCallback\<string>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getAppType((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
console.info("getAppType err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -1013,10 +1006,10 @@ getAppType(): Promise\<string>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getAppType().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
console.info("getAppType data: " + JSON.stringify(data));
});
```
......@@ -1037,14 +1030,10 @@ getHapModuleInfo(callback: AsyncCallback\<HapModuleInfo>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getHapModuleInfo((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
console.info("getHapModuleInfo err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -1065,10 +1054,10 @@ getHapModuleInfo(): Promise\<HapModuleInfo>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getHapModuleInfo().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
console.info("getHapModuleInfo data: " + JSON.stringify(data));
});
```
......@@ -1089,14 +1078,10 @@ getAppVersionInfo(callback: AsyncCallback\<AppVersionInfo>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getAppVersionInfo((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
console.info("getAppVersionInfo err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -1117,10 +1102,10 @@ getAppVersionInfo(): Promise\<AppVersionInfo>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getAppVersionInfo().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
console.info("getAppVersionInfo data: " + JSON.stringify(data));
});
```
......@@ -1141,14 +1126,10 @@ getAbilityInfo(callback: AsyncCallback\<AbilityInfo>): void
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getAbilityInfo((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
console.info("getAbilityInfo err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -1169,10 +1150,10 @@ getAbilityInfo(): Promise\<AbilityInfo>
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.getAbilityInfo().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
console.info("getAbilityInfo data: " + JSON.stringify(data));
});
```
......@@ -1193,7 +1174,7 @@ getApplicationContext(): Context
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext().getApplicationContext();
```
......@@ -1214,14 +1195,10 @@ isUpdatingConfigurations(callback: AsyncCallback\<boolean>): void;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.isUpdatingConfigurations((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
console.info("isUpdatingConfigurations err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
......@@ -1242,10 +1219,10 @@ isUpdatingConfigurations(): Promise\<boolean>;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.isUpdatingConfigurations().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
console.info("isUpdatingConfigurations data: " + JSON.stringify(data));
});
```
......@@ -1266,14 +1243,10 @@ printDrawnCompleted(callback: AsyncCallback\<void>): void;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.printDrawnCompleted((err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
console.error('printDrawnCompleted err: ' + JSON.stringify(err));
});
```
......@@ -1294,10 +1267,10 @@ printDrawnCompleted(): Promise\<void>;
**示例:**
```js
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext();
context.printDrawnCompleted().then((data) => {
console.info("====>data====>" + JSON.stringify(data));
console.info("printDrawnCompleted data: " + JSON.stringify(data));
});
```
......
......@@ -33,13 +33,13 @@ onConfigurationUpdated(config: Configuration): void;
```js
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
var callbackId;
export default class MyAbilityStage extends AbilityStage {
export default class MyAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MyAbility onCreate")
globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = {
onConfigurationUpdated(config){
......
......@@ -157,11 +157,11 @@ onAbilityContinue(ability: Ability): void;
```js
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
export default class MyAbilityStage extends AbilityStage {
export default class MyAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MyAbility onCreate")
let AbilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
......@@ -200,6 +200,12 @@ onAbilityContinue(ability: Ability): void;
// 2.通过applicationContext注册监听应用内生命周期
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.unregisterAbilityLifecycleCallback(lifecycleid, (error, data) => {
console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
});
}
}
```
\ No newline at end of file
......@@ -39,13 +39,13 @@ registerAbilityLifecycleCallback(callback: AbilityLifecycleCallback): **number**
**示例:**
```js
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
var lifecycleId;
export default class MyAbilityStage extends AbilityStage {
export default class MyAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MyAbility onCreate")
let AbilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
......@@ -84,7 +84,7 @@ export default class MyAbilityStage extends AbilityStage {
// 2.通过applicationContext注册监听应用内生命周期
lifecycleId = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleId));
}
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.unregisterAbilityLifecycleCallback(lifecycleId, (error, data) => {
......@@ -144,13 +144,13 @@ registerEnvironmentCallback(callback: EnvironmentCallback): **number**;
**示例:**
```js
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
var callbackId;
export default class MyAbilityStage extends AbilityStage {
export default class MyAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MyAbility onCreate")
globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = {
onConfigurationUpdated(config){
......
......@@ -14,7 +14,7 @@ FeatureAbility模块的接口只能在Page类型的Ability调用
## 导入模块
```
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
```
## featureAbility.startAbility
......@@ -35,8 +35,8 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>)
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureAbility'
import wantConstant from '@ohos.ability.wantConstant'
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbility(
{
want:
......@@ -52,6 +52,9 @@ featureAbility.startAbility(
uri: ""
},
},
(err, data) => {
console.info("startAbility err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
}
);
```
......@@ -74,8 +77,8 @@ startAbility(parameter: StartAbilityParameter): Promise\<number>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureAbility'
import wantConstant from '@ohos.ability.wantConstant'
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbility(
{
want:
......@@ -83,7 +86,7 @@ featureAbility.startAbility(
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
/* FA模型中abilityName由package + Ability name组成 */
......@@ -92,7 +95,7 @@ featureAbility.startAbility(
},
}
).then((data) => {
console.info("==========================>startAbility=======================>");
console.info("startAbility data: " + JSON.stringify(data));
});
```
......@@ -119,10 +122,10 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureAbility'
featureAbility.acquireDataAbilityHelper(
import featureAbility from '@ohos.ability.featureAbility';
var dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
)
);
```
## featureAbility.startAbilityForResult<sup>7+</sup>
......@@ -144,7 +147,7 @@ startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\
```javascript
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbilityForResult(
{
want:
......@@ -161,9 +164,9 @@ featureAbility.startAbilityForResult(
},
},
(err, data) => {
console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
console.info("startAbilityForResult err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
}
)
);
```
## featureAbility.startAbilityForResult<sup>7+</sup>
......@@ -190,7 +193,7 @@ startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbilityForResult(
{
want:
......@@ -218,7 +221,7 @@ featureAbility.startAbilityForResult(
},
},
).then((data) => {
console.info("==========================>startAbilityForResult=======================>");
console.info("startAbilityForResult data: " + JSON.stringify(data));
});
```
......@@ -240,8 +243,8 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureAbility'
import wantConstant from '@ohos.ability.wantConstant'
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.terminateSelfWithResult(
{
resultCode: 1,
......@@ -295,7 +298,7 @@ terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.terminateSelfWithResult(
{
resultCode: 1,
......@@ -345,7 +348,9 @@ hasWindowFocus(callback: AsyncCallback\<boolean>): void
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus()
featureAbility.hasWindowFocus((err, data) => {
console.info("hasWindowFocus err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
## featureAbility.hasWindowFocus<sup>7+<sup>
......@@ -367,7 +372,7 @@ hasWindowFocus(): Promise\<boolean>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus().then((data) => {
console.info("==========================>hasWindowFocus=======================>");
console.info("hasWindowFocus data: " + JSON.stringify(data));
});
```
......@@ -389,7 +394,9 @@ getWant(callback: AsyncCallback\<Want>): void
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant()
featureAbility.getWant((err, data) => {
console.info("getWant err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
## featureAbility.getWant
......@@ -411,7 +418,7 @@ getWant(): Promise\<Want>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant().then((data) => {
console.info("==========================>getWantCallBack=======================>");
console.info("getWant data: " + JSON.stringify(data));
});
```
......@@ -434,7 +441,9 @@ getContext(): Context
```javascript
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext()
context.getBundleName()
context.getBundleName((err, data) => {
console.info("getBundleName err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
## featureAbility.terminateSelf<sup>7+</sup>
......@@ -455,7 +464,7 @@ terminateSelf(callback: AsyncCallback\<void>): void
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf()
featureAbility.terminateSelf();
```
## featureAbility.terminateSelf<sup>7+</sup>
......@@ -477,7 +486,7 @@ terminateSelf(): Promise\<void>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf().then((data) => {
console.info("==========================>terminateSelfCallBack=======================>");
console.info("==========================>terminateSelf=======================>");
});
```
......@@ -517,8 +526,8 @@ ConnectOptions类型说明
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -528,7 +537,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
......@@ -560,8 +569,8 @@ disconnectAbility(connection: number, callback:AsyncCallback\<void>): void
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -571,7 +580,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -582,7 +591,7 @@ var connId = featureAbility.connectAbility(
onFailed: onFailedCallback,
},
);
var result = featureAbility.disconnectAbility(connId,
var result = featureAbility.disconnectAbility(connectId,
(error,data) => {
console.log('featureAbilityTest DisConnectJsSameBundleName result errCode : ' + error.code + " data: " + data)
},
......@@ -612,8 +621,8 @@ disconnectAbility(connection: number): Promise\<void>
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -623,7 +632,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -635,7 +644,7 @@ var connId = featureAbility.connectAbility(
},
);
featureAbility.disconnectAbility(connId).then((data) => {
featureAbility.disconnectAbility(connectId).then((data) => {
console.log('data : ' + data);
}).catch((error)=>{
console.log('featureAbilityTest result errCode : ' + error.code);
......@@ -660,7 +669,9 @@ getWindow(callback: AsyncCallback\<window.Window>): void
**示例:**
```javascript
featureAbility.getWindow()
featureAbility.getWindow((err, data) => {
console.info("getWindow err: " + JSON.stringify(err) + "data: " + typeof(data));
});
```
## featureAbility.getWindow<sup>7+</sup>
......@@ -681,7 +692,7 @@ getWindow(): Promise\<window.Window>;
```javascript
featureAbility.getWindow().then((data) => {
console.info("=============getWindowPromise========== " + JSON.stringify(data));
console.info("getWindow data: " + typeof(data));
});
```
......@@ -703,8 +714,8 @@ onConnect(elementName: ElementName, remote: rpc.IRemoteObject): void;
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -714,7 +725,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
......@@ -745,8 +756,8 @@ onDisconnect(elementName: ElementName): void;
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -756,7 +767,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
......@@ -787,8 +798,8 @@ ConnectAbility调用失败时的回调函数。
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -798,7 +809,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
......
......@@ -415,7 +415,7 @@ connectAbility(request: Want, options:ConnectOptions): number
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
var connectId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -427,7 +427,7 @@ connectAbility(request: Want, options:ConnectOptions): number
},
);
particleAbility.disconnectAbility(connId).then((data)=>{
particleAbility.disconnectAbility(connectId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
......@@ -464,7 +464,7 @@ import rpc from '@ohos.rpc'
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
var connectId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -475,7 +475,7 @@ import rpc from '@ohos.rpc'
onFailed: onFailedCallback,
},
);
var result = particleAbility.disconnectAbility(connId).then((data)=>{
var result = particleAbility.disconnectAbility(connectId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
......@@ -511,7 +511,7 @@ function onConnectCallback(element, remote){
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
var connectId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -523,7 +523,7 @@ function onConnectCallback(element, remote){
},
);
particleAbility.disconnectAbility(connId).then((data)=>{
particleAbility.disconnectAbility(connectId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册