提交 e53420cc 编写于 作者: M mingxihua

mingxihua@huawei.com.cn

Signed-off-by: Nmingxihua <mingxihua@huawei.com>
上级 60515c3b
......@@ -10,7 +10,7 @@ Ability模块将二级模块API组织在一起方便开发者进行导出。
## 导入模块
```ts
import ability from '@ohos.ability.ability'
import ability from '@ohos.ability.ability';
```
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
......
......@@ -16,7 +16,7 @@ AbilityContext模块提供允许访问特定Ability的资源的能力,包括
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
let context = undefined;
let context;
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
context = this.context;
......@@ -66,8 +66,8 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "MyAbility"
bundleName: 'com.example.myapplication',
abilityName: 'MyAbility'
};
try {
......@@ -122,9 +122,9 @@ startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let options = {
windowMode: 0
......@@ -186,8 +186,8 @@ startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "MyAbility"
bundleName: 'com.example.myapplication',
abilityName: 'MyAbility'
};
let options = {
windowMode: 0,
......@@ -247,9 +247,9 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;):
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
try {
......@@ -261,8 +261,8 @@ startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;):
return;
}
// 执行正常业务
console.log("startAbilityForResult succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResult succeed, result.resultCode = ' +
result.resultCode);
});
} catch (paramError) {
// 处理入参错误异常
......@@ -307,9 +307,9 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let options = {
windowMode: 0,
......@@ -324,8 +324,8 @@ startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback
return;
}
// 执行正常业务
console.log("startAbilityForResult succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResult succeed, result.resultCode = ' +
result.resultCode);
});
} catch (paramError) {
// 处理入参错误异常
......@@ -377,8 +377,8 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "MyAbility"
bundleName: 'com.example.myapplication',
abilityName: 'MyAbility'
};
let options = {
windowMode: 0,
......@@ -388,7 +388,7 @@ startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityRes
this.context.startAbilityForResult(want, options)
.then((result) => {
// 执行正常业务
console.log("startAbilityForResult succeed, result.resultCode = " + result.resultCode);
console.log('startAbilityForResult succeed, result.resultCode = ' + result.resultCode);
})
.catch((error) => {
// 处理业务逻辑错误
......@@ -439,9 +439,9 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
......@@ -454,8 +454,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, callback: AsyncC
return;
}
// 执行正常业务
console.log("startAbilityForResultWithAccount succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResultWithAccount succeed, result.resultCode = ' +
result.resultCode);
});
} catch (paramError) {
// 处理入参错误异常
......@@ -503,9 +503,9 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
let options = {
......@@ -521,8 +521,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options: StartOp
return;
}
// 执行正常业务
console.log("startAbilityForResultWithAccount succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResultWithAccount succeed, result.resultCode = ' +
result.resultCode);
});
} catch (paramError) {
// 处理入参错误异常
......@@ -575,9 +575,9 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
let options = {
......@@ -588,8 +588,8 @@ startAbilityForResultWithAccount(want: Want, accountId: number, options?: StartO
this.context.startAbilityForResultWithAccount(want, accountId, options)
.then((result) => {
// 执行正常业务
console.log("startAbilityForResultWithAccount succeed, result.resultCode = " +
result.resultCode)
console.log('startAbilityForResultWithAccount succeed, result.resultCode = ' +
result.resultCode);
})
.catch((error) => {
// 处理业务逻辑错误
......@@ -631,9 +631,9 @@ startServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
try {
......@@ -682,9 +682,9 @@ startServiceExtensionAbility(want: Want): Promise\<void>;
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
try {
......@@ -737,9 +737,9 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
......@@ -792,9 +792,9 @@ startServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
......@@ -844,20 +844,20 @@ stopServiceExtensionAbility(want: Want, callback: AsyncCallback\<void>): void;
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
try {
this.context.startAbility(want, (error) => {
if (error.code != 0) {
console.log("start ability fail, err: " + JSON.stringify(err));
if (error.code !== 0) {
console.log('start ability fail, err: ' + JSON.stringify(err));
}
})
this.context.stopServiceExtensionAbility(want, (error) => {
if (error.code != 0) {
if (error.code !== 0) {
// 处理业务逻辑错误
console.log('stopServiceExtensionAbility failed, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
......@@ -901,15 +901,15 @@ stopServiceExtensionAbility(want: Want): Promise\<void>;
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
try {
this.context.startAbility(want, (error) => {
if (error.code != 0) {
console.log("start ability fail, err: " + JSON.stringify(err));
if (error.code !== 0) {
console.log('start ability fail, err: ' + JSON.stringify(err));
}
})
......@@ -962,16 +962,16 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number, callback:
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
try {
this.context.startAbilityWithAccount(want, accountId, (error) => {
if (error.code != 0) {
console.log("start ability fail, err: " + JSON.stringify(err));
if (error.code !== 0) {
console.log('start ability fail, err: ' + JSON.stringify(err));
}
})
......@@ -1023,16 +1023,16 @@ stopServiceExtensionAbilityWithAccount(want: Want, accountId: number): Promise\<
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
try {
this.context.startAbilityWithAccount(want, accountId, (error) => {
if (error.code != 0) {
console.log("start ability fail, err: " + JSON.stringify(err));
if (error.code !== 0) {
console.log('start ability fail, err: ' + JSON.stringify(err));
}
})
......@@ -1154,15 +1154,15 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;voi
```ts
let want = {
bundleName: "com.extreme.myapplication",
abilityName: "SecondAbility"
}
bundleName: 'com.extreme.myapplication',
abilityName: 'SecondAbility'
};
let resultCode = 100;
// 返回给接口调用方AbilityResult信息
let abilityResult = {
want,
resultCode
}
};
try {
this.context.terminateSelfWithResult(abilityResult, (error) => {
......@@ -1217,15 +1217,15 @@ terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;
```ts
let want = {
bundleName: "com.extreme.myapplication",
abilityName: "SecondAbility"
}
bundleName: 'com.extreme.myapplication',
abilityName: 'SecondAbility'
};
let resultCode = 100;
// 返回给接口调用方AbilityResult信息
let abilityResult = {
want,
resultCode
}
};
try {
this.context.terminateSelfWithResult(abilityResult)
......@@ -1280,15 +1280,15 @@ connectServiceExtensionAbility(want: Want, options: ConnectOptions): number;
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.log('----------- onFailed -----------') }
}
};
let connection = null;
try {
......@@ -1339,16 +1339,16 @@ connectServiceExtensionAbilityWithAccount(want: Want, accountId: number, options
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
let options = {
onConnect(elementName, remote) { console.log('----------- onConnect -----------') },
onDisconnect(elementName) { console.log('----------- onDisconnect -----------') },
onFailed(code) { console.log('----------- onFailed -----------') }
}
};
let connection = null;
try {
......@@ -1491,14 +1491,14 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
后台启动:
```ts
let caller = undefined;
let caller;
// 后台启动Ability,不配置parameters
let wantBackground = {
bundleName: "com.example.myservice",
moduleName: "entry",
abilityName: "EntryAbility",
deviceId: ""
bundleName: 'com.example.myservice',
moduleName: 'entry',
abilityName: 'EntryAbility',
deviceId: ''
};
try {
......@@ -1522,16 +1522,16 @@ startAbilityByCall(want: Want): Promise&lt;Caller&gt;;
前台启动:
```ts
let caller = undefined;
let caller;
// 前台启动Ability,将parameters中的"ohos.aafwk.param.callAbilityToForeground"配置为true
// 前台启动Ability,将parameters中的'ohos.aafwk.param.callAbilityToForeground'配置为true
let wantForeground = {
bundleName: "com.example.myservice",
moduleName: "entry",
abilityName: "EntryAbility",
deviceId: "",
bundleName: 'com.example.myservice',
moduleName: 'entry',
abilityName: 'EntryAbility',
deviceId: '',
parameters: {
"ohos.aafwk.param.callAbilityToForeground": true
'ohos.aafwk.param.callAbilityToForeground': true
}
};
......@@ -1590,9 +1590,9 @@ startAbilityWithAccount(want: Want, accountId: number, callback: AsyncCallback\<
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
......@@ -1653,9 +1653,9 @@ startAbilityWithAccount(want: Want, accountId: number, options: StartOptions, ca
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
let options = {
......@@ -1718,9 +1718,9 @@ startAbilityWithAccount(want: Want, accountId: number, options?: StartOptions):
```ts
let want = {
deviceId: "",
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
deviceId: '',
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let accountId = 100;
let options = {
......@@ -1763,7 +1763,7 @@ setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;
**示例:**
```ts
this.context.setMissionLabel("test",(result) => {
this.context.setMissionLabel('test',(result) => {
console.log('setMissionLabel result:' + JSON.stringify(result));
});
```
......@@ -1792,7 +1792,7 @@ setMissionLabel(label: string): Promise&lt;void&gt;;
**示例:**
```ts
this.context.setMissionLabel("test").then(() => {
this.context.setMissionLabel('test').then(() => {
console.log('success');
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
......@@ -1832,7 +1832,7 @@ setMissionIcon(icon: image.PixelMap, callback:AsyncCallback\<void>): void;
imagePixelMap = data;
})
.catch((err) => {
console.log('--------- createPixelMap fail, err: ---------', err)
console.log('--------- createPixelMap fail, err: ---------', err);
});
this.context.setMissionIcon(imagePixelMap, (err) => {
console.log('---------- setMissionIcon fail, err: -----------', err);
......@@ -1879,7 +1879,7 @@ setMissionIcon(icon: image.PixelMap): Promise\<void>;
imagePixelMap = data;
})
.catch((err) => {
console.log('--------- createPixelMap fail, err: ---------', err)
console.log('--------- createPixelMap fail, err: ---------', err);
});
this.context.setMissionIcon(imagePixelMap)
.then(() => {
......
......@@ -35,7 +35,7 @@ getId(uri: string): number
**示例:**
```ts
let id = dataUriUtils.getId("com.example.dataUriUtils/1221");
let id = dataUriUtils.getId('com.example.dataUriUtils/1221');
```
......@@ -66,9 +66,9 @@ attachId(uri: string, id: number): string
```ts
let id = 1122;
let uri = dataUriUtils.attachId(
"com.example.dataUriUtils",
'com.example.dataUriUtils',
id,
)
);
```
......@@ -96,7 +96,7 @@ deleteId(uri: string): string
**示例:**
```ts
let uri = dataUriUtils.deleteId("com.example.dataUriUtils/1221")
let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221');
```
......@@ -127,8 +127,8 @@ updateId(uri: string, id: number): string
```ts
let id = 1122;
let uri = dataUriUtils.updateId(
"com.example.dataUriUtils/1221",
'com.example.dataUriUtils/1221',
id
)
);
```
......@@ -9,7 +9,7 @@ ErrorCode定义启动Ability时返回的错误码,包括无效的参数、权
## 导入模块
```ts
import errorCode from '@ohos.ability.errorCode'
import errorCode from '@ohos.ability.errorCode';
```
## ErrorCode
......
......@@ -46,19 +46,19 @@ featureAbility.startAbility(
{
want:
{
action: "",
entities: [""],
type: "",
action: '',
entities: [''],
type: '',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri: ""
abilityName: 'com.example.myapplication.secondAbility',
uri: ''
},
},
(err, data) => {
console.info("startAbility err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('startAbility err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
}
);
```
......@@ -99,19 +99,19 @@ featureAbility.startAbility(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri: ""
abilityName: 'com.example.myapplication.secondAbility',
uri: ''
},
}
).then((data) => {
console.info("startAbility data: " + JSON.stringify(data));
console.info('startAbility data: ' + JSON.stringify(data));
});
```
......@@ -146,7 +146,7 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
```ts
import featureAbility from '@ohos.ability.featureAbility';
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
'dataability:///com.example.DataAbility'
);
```
......@@ -182,19 +182,19 @@ featureAbility.startAbilityForResult(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri:""
abilityName: 'com.example.myapplication.secondAbility',
uri:''
},
},
(err, data) => {
console.info("startAbilityForResult err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('startAbilityForResult err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
}
);
```
......@@ -236,30 +236,30 @@ featureAbility.startAbilityForResult(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri:"",
abilityName: 'com.example.myapplication.secondAbility',
uri:'',
parameters:
{
mykey0: 1111,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "xxxxxxxxxxxxxxxxxxxxxx",
mykey2: '[1, 2, 3]',
mykey3: 'xxxxxxxxxxxxxxxxxxxxxx',
mykey4: [1, 15],
mykey5: [false, true, false],
mykey6: ["aaaaaa", "bbbbb", "ccccccccccc"],
mykey6: ['aaaaaa', 'bbbbb', 'ccccccccccc'],
mykey7: true,
},
},
},
).then((data) => {
console.info("startAbilityForResult data: " + JSON.stringify(data));
console.info('startAbilityForResult data: ' + JSON.stringify(data));
});
```
......@@ -288,29 +288,29 @@ featureAbility.terminateSelfWithResult(
resultCode: 1,
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri:"",
abilityName: 'com.example.myapplication.secondAbility',
uri:'',
parameters: {
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey2: '[1, 2, 3]',
mykey3: 'ssssssssssssssssssssssssss',
mykey4: [1, 15],
mykey5: [false, true, false],
mykey6: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
mykey7: true,
}
},
},
(err) => {
console.info("err: " + JSON.stringify(err))
console.error('err: ' + JSON.stringify(err));
}
);
```
......@@ -345,29 +345,29 @@ featureAbility.terminateSelfWithResult(
resultCode: 1,
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
deviceId: '',
bundleName: 'com.example.myapplication',
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.myapplication.secondAbility",
uri:"",
abilityName: 'com.example.myapplication.secondAbility',
uri:'',
parameters: {
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey2: '[1, 2, 3]',
mykey3: 'ssssssssssssssssssssssssss',
mykey4: [1, 15],
mykey5: [false, true, false],
mykey6: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: ['qqqqq', 'wwwwww', 'aaaaaaaaaaaaaaaaa'],
mykey7: true,
}
},
}
).then((data) => {
console.info("==========================>terminateSelfWithResult=======================>");
console.info('==========================>terminateSelfWithResult=======================>');
});
```
......@@ -390,7 +390,7 @@ hasWindowFocus(callback: AsyncCallback\<boolean>): void
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus((err, data) => {
console.info("hasWindowFocus err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('hasWindowFocus err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
});
```
......@@ -413,7 +413,7 @@ hasWindowFocus(): Promise\<boolean>
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus().then((data) => {
console.info("hasWindowFocus data: " + JSON.stringify(data));
console.info('hasWindowFocus data: ' + JSON.stringify(data));
});
```
......@@ -436,7 +436,7 @@ getWant(callback: AsyncCallback\<Want>): void
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant((err, data) => {
console.info("getWant err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('getWant err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
});
```
......@@ -459,7 +459,7 @@ getWant(): Promise\<Want>
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant().then((data) => {
console.info("getWant data: " + JSON.stringify(data));
console.info('getWant data: ' + JSON.stringify(data));
});
```
......@@ -481,9 +481,9 @@ getContext(): Context
```ts
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext()
let context = featureAbility.getContext();
context.getBundleName((err, data) => {
console.info("getBundleName err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
console.info('getBundleName err: ' + JSON.stringify(err) + 'data: ' + JSON.stringify(data));
});
```
......@@ -507,7 +507,7 @@ terminateSelf(callback: AsyncCallback\<void>): void
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf(
(err) => {
console.info("err: " + JSON.stringify(err))
console.error('err: ' + JSON.stringify(err));
}
)
```
......@@ -531,7 +531,7 @@ terminateSelf(): Promise\<void>
```ts
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf().then((data) => {
console.info("==========================>terminateSelf=======================>");
console.info('==========================>terminateSelf=======================>');
});
```
......@@ -578,9 +578,9 @@ function onFailedCallback(code){
}
let connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
abilityName: "com.ix.ServiceAbility.ServiceAbilityA",
deviceId: '',
bundleName: 'com.ix.ServiceAbility',
abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -614,15 +614,15 @@ function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "com.ix.ServiceAbility.ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -632,8 +632,8 @@ let connectId = featureAbility.connectAbility(
);
featureAbility.disconnectAbility(connectId, (err) => {
console.log("featureAbilityTest disconnectAbility err====>"
+ ("json err=") + JSON.stringify(err));
console.error('featureAbilityTest disconnectAbility err====>'
+ ('json err=') + JSON.stringify(err));
});
```
......@@ -666,15 +666,15 @@ function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "com.ix.ServiceAbility.ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'com.ix.ServiceAbility.ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -686,7 +686,7 @@ let connectId = featureAbility.connectAbility(
featureAbility.disconnectAbility(connectId).then((data) => {
console.log('data : ' + data);
}).catch((error)=>{
console.log('featureAbilityTest result errCode : ' + error.code);
console.error('featureAbilityTest result errCode : ' + error.code);
});
```
......@@ -709,7 +709,7 @@ getWindow(callback: AsyncCallback\<window.Window>): void
```ts
featureAbility.getWindow((err, data) => {
console.info("getWindow err: " + JSON.stringify(err) + "data: " + typeof(data));
console.info('getWindow err: ' + JSON.stringify(err) + 'data: ' + typeof(data));
});
```
......@@ -731,7 +731,7 @@ getWindow(): Promise\<window.Window>;
```ts
featureAbility.getWindow().then((data) => {
console.info("getWindow data: " + typeof(data));
console.info('getWindow data: ' + typeof(data));
});
```
......@@ -772,9 +772,9 @@ featureAbility.AbilityStartSetting.BOUNDS_KEY
| 名称 | 值 | 说明 |
| ---------------------------- | --------------- | ---------------------------------------- |
| BOUNDS_KEY<sup>7+</sup> | "abilityBounds" | 窗口显示大小属性的参数名。 |
| WINDOW_MODE_KEY<sup>7+</sup> | "windowMode" | 窗口显示模式属性的参数名。|
| DISPLAY_ID_KEY<sup>7+</sup> | "displayId" | 窗口显示设备ID属性的参数名。 |
| BOUNDS_KEY<sup>7+</sup> | 'abilityBounds' | 窗口显示大小属性的参数名。 |
| WINDOW_MODE_KEY<sup>7+</sup> | 'windowMode' | 窗口显示模式属性的参数名。|
| DISPLAY_ID_KEY<sup>7+</sup> | 'displayId' | 窗口显示设备ID属性的参数名。 |
## ErrorCode
......
......@@ -14,7 +14,7 @@ particleAbility模块用来对Data和Service类型的Ability进行操作。
## 导入模块
```ts
import particleAbility from '@ohos.ability.particleAbility'
import particleAbility from '@ohos.ability.particleAbility';
```
## particleAbility.startAbility
......@@ -40,27 +40,27 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>):
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from '@ohos.ability.wantConstant'
import particleAbility from '@ohos.ability.particleAbility';
import wantConstant from '@ohos.ability.wantConstant';
particleAbility.startAbility(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.Data",
abilityName: "EntryAbility",
uri: ""
deviceId: '',
bundleName: 'com.example.Data',
abilityName: 'EntryAbility',
uri: ''
},
},
(error, result) => {
console.log('particleAbility startAbility errCode:' + error + 'result:' + result)
console.error('particleAbility startAbility errCode:' + error + 'result:' + result);
},
)
);
```
## particleAbility.startAbility
......@@ -91,25 +91,25 @@ startAbility(parameter: StartAbilityParameter): Promise\<void>;
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from '@ohos.ability.wantConstant'
import particleAbility from '@ohos.ability.particleAbility';
import wantConstant from '@ohos.ability.wantConstant';
particleAbility.startAbility(
{
want:
{
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
action: 'action.system.home',
entities: ['entity.system.home'],
type: 'MIMETYPE',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.Data",
abilityName: "EntryAbility",
uri: ""
deviceId: '',
bundleName: 'com.example.Data',
abilityName: 'EntryAbility',
uri: ''
},
},
).then((data) => {
console.info("particleAbility startAbility");
console.info('particleAbility startAbility');
});
```
......@@ -130,13 +130,13 @@ terminateSelf(callback: AsyncCallback\<void>): void
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import particleAbility from '@ohos.ability.particleAbility';
particleAbility.terminateSelf(
(error, result) => {
console.log('particleAbility terminateSelf errCode:' + error + 'result:' + result)
console.log('particleAbility terminateSelf errCode:' + error + 'result:' + result);
}
)
);
```
## particleAbility.terminateSelf
......@@ -156,10 +156,10 @@ terminateSelf(): Promise\<void>
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import particleAbility from '@ohos.ability.particleAbility';
particleAbility.terminateSelf().then((data) => {
console.info("particleAbility terminateSelf");
console.info('particleAbility terminateSelf');
});
```
......@@ -194,10 +194,10 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
**示例:**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import particleAbility from '@ohos.ability.particleAbility';
let uri = "";
particleAbility.acquireDataAbilityHelper(uri)
let uri = '';
particleAbility.acquireDataAbilityHelper(uri);
```
......@@ -228,17 +228,17 @@ import wantAgent from '@ohos.app.ability.wantAgent';
function callback(err, data) {
if (err) {
console.error("Operation failed cause: " + JSON.stringify(err));
console.error('Operation failed cause: ' + JSON.stringify(err));
} else {
console.info("Operation succeeded");
console.info('Operation succeeded');
}
}
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
}
],
operationType: wantAgent.OperationType.START_ABILITY,
......@@ -248,8 +248,8 @@ let wantAgentInfo = {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let basicContent = {
title: "title",
text: "text"
title: 'title',
text: 'text'
};
let notificationContent = {
contentType: notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
......@@ -298,8 +298,8 @@ import wantAgent from '@ohos.app.ability.wantAgent';
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
}
],
operationType: wantAgent.OperationType.START_ABILITY,
......@@ -309,8 +309,8 @@ let wantAgentInfo = {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let basicContent = {
title: "title",
text: "text"
title: 'title',
text: 'text'
};
let notificationContent = {
contentType: notification.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
......@@ -322,9 +322,9 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
};
let id = 1;
particleAbility.startBackgroundRunning(id, request).then(() => {
console.info("Operation succeeded");
console.info('Operation succeeded');
}).catch((err) => {
console.error("Operation failed cause: " + JSON.stringify(err));
console.error('Operation failed cause: ' + JSON.stringify(err));
});
});
......@@ -351,9 +351,9 @@ import particleAbility from '@ohos.ability.particleAbility';
function callback(err, data) {
if (err) {
console.error("Operation failed cause: " + JSON.stringify(err));
console.error('Operation failed cause: ' + JSON.stringify(err));
} else {
console.info("Operation succeeded");
console.info('Operation succeeded');
}
}
......@@ -381,9 +381,9 @@ cancelBackgroundRunning(): Promise&lt;void&gt;;
import particleAbility from '@ohos.ability.particleAbility';
particleAbility.cancelBackgroundRunning().then(() => {
console.info("Operation succeeded");
console.info('Operation succeeded');
}).catch((err) => {
console.error("Operation failed cause: " + JSON.stringify(err));
console.error('Operation failed cause: ' + JSON.stringify(err));
});
```
......@@ -413,25 +413,25 @@ connectAbility(request: Want, options:ConnectOptions): number
**示例**
```ts
import particleAbility from '@ohos.ability.particleAbility'
import rpc from '@ohos.rpc'
import particleAbility from '@ohos.ability.particleAbility';
import rpc from '@ohos.rpc';
function onConnectCallback(element, remote) {
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
function onDisconnectCallback(element) {
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -441,9 +441,9 @@ let connId = particleAbility.connectAbility(
);
particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
console.log(' data: ' + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
console.log('particleAbilityTest result errCode : ' + error.code);
});
```
......@@ -472,17 +472,17 @@ function onConnectCallback(element, remote) {
}
function onDisconnectCallback(element) {
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -492,8 +492,8 @@ let connId = particleAbility.connectAbility(
);
particleAbility.disconnectAbility(connId, (err) => {
console.log("particleAbilityTest disconnectAbility err====>"
+ ("json err=") + JSON.stringify(err));
console.log('particleAbilityTest disconnectAbility err====>'
+ ('json err=') + JSON.stringify(err));
});
```
......@@ -523,17 +523,17 @@ function onConnectCallback(element, remote) {
}
function onDisconnectCallback(element) {
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId);
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code);
}
let connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
bundleName: 'com.ix.ServiceAbility',
abilityName: 'ServiceAbilityA',
},
{
onConnect: onConnectCallback,
......@@ -543,9 +543,9 @@ let connId = particleAbility.connectAbility(
);
particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
console.log(' data: ' + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
console.log('particleAbilityTest result errCode : ' + error.code);
});
```
......
......@@ -48,7 +48,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launchParam.launchReason === AbilityConstant.LaunchReason.START_ABILITY) {
console.log("The ability has been started by the way of startAbility.");
console.log('The ability has been started by the way of startAbility.');
}
}
}
......@@ -74,7 +74,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onCreate(want, launchParam) {
if (launchParam.lastExitReason === AbilityConstant.LastExitReason.ABILITY_NOT_RESPONDING) {
console.log("The ability has exit last because the ability was not responding.");
console.log('The ability has exit last because the ability was not responding.');
}
}
}
......@@ -124,8 +124,8 @@ class MyAbility extends UIAbility {
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
let option = {
windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FULLSCREEN
......@@ -133,9 +133,9 @@ let option = {
// 确保从上下文获取到context
this.context.startAbility(want, option).then(()={
console.log("Succeed to start ability.");
console.log('Succeed to start ability.');
}).catch((error)=>{
console.log("Failed to start ability with error: " + JSON.stringify(error));
console.log('Failed to start ability with error: ' + JSON.stringify(error));
});
```
......@@ -159,7 +159,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onMemoryLevel(level) {
if (level === AbilityConstant.MemoryLevel.MEMORY_LEVEL_CRITICAL) {
console.log("The memory of device is critical, please release some memory.");
console.log('The memory of device is critical, please release some memory.');
}
}
}
......@@ -211,7 +211,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class MyAbility extends UIAbility {
onSaveState(reason, wantParam) {
if (reason === AbilityConstant.StateType.CONTINUATION) {
console.log("Save the ability data when the ability continuation.");
console.log('Save the ability data when the ability continuation.');
}
return AbilityConstant.OnSaveResult.ALL_AGREE;
}
......
......@@ -49,16 +49,16 @@ import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let want = {
bundleName: "com.example.myapplication",
abilityName: "EntryAbility"
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility'
};
abilityDelegator.startAbility(want, (err) => {
if (!err || err.code === 0) {
console.log("Success start ability.");
console.log('Success start ability.');
} else {
console.log("Failed start ability, error: " + JSON.stringify(err));
console.log('Failed start ability, error: ' + JSON.stringify(err));
}
})
});
```
## AbilityDelegatorRegistry.getArguments
......@@ -81,8 +81,8 @@ getArguments(): AbilityDelegatorArgs
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
let args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName);
console.info("getArguments parameters:" + JSON.stringify(args.parameters));
console.info("getArguments testCaseNames:" + args.testCaseNames);
console.info("getArguments testRunnerClassName:" + args.testRunnerClassName);
console.info('getArguments bundleName:' + args.bundleName);
console.info('getArguments parameters:' + JSON.stringify(args.parameters));
console.info('getArguments testCaseNames:' + args.testCaseNames);
console.info('getArguments testRunnerClassName:' + args.testRunnerClassName);
```
......@@ -11,7 +11,7 @@ AbilityLifecycleCallback模块提供应用上下文[ApplicationContext](js-apis-
## 导入模块
```ts
import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback";
import AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback';
```
......@@ -33,7 +33,7 @@ onAbilityCreate(ability: UIAbility): void;
```ts
let abilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate.");
console.log('AbilityLifecycleCallback onAbilityCreate.');
}
};
```
......@@ -57,7 +57,7 @@ onWindowStageCreate(ability: UIAbility, windowStage: window.WindowStage): void;
```ts
let abilityLifecycleCallback = {
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate.");
console.log('AbilityLifecycleCallback onWindowStageCreate.');
}
};
```
......@@ -81,7 +81,7 @@ onWindowStageActive(ability: UIAbility, windowStage: window.WindowStage): void;
```ts
let abilityLifecycleCallback = {
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive.");
console.log('AbilityLifecycleCallback onWindowStageActive.');
}
};
```
......@@ -105,7 +105,7 @@ onWindowStageInactive(ability: UIAbility, windowStage: window.WindowStage): void
```ts
let abilityLifecycleCallback = {
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive.");
console.log('AbilityLifecycleCallback onWindowStageInactive.');
}
};
```
......@@ -129,7 +129,7 @@ onWindowStageDestroy(ability: UIAbility, windowStage: window.WindowStage): void;
```ts
let abilityLifecycleCallback = {
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy.");
console.log('AbilityLifecycleCallback onWindowStageDestroy.');
}
};
```
......@@ -152,7 +152,7 @@ onAbilityDestroy(ability: UIAbility): void;
```ts
let abilityLifecycleCallback = {
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy.");
console.log('AbilityLifecycleCallback onAbilityDestroy.');
}
};
```
......@@ -175,7 +175,7 @@ onAbilityForeground(ability: UIAbility): void;
```ts
let abilityLifecycleCallback = {
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground.");
console.log('AbilityLifecycleCallback onAbilityForeground.');
}
};
```
......@@ -198,7 +198,7 @@ onAbilityBackground(ability: UIAbility): void;
```ts
let abilityLifecycleCallback = {
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground.");
console.log('AbilityLifecycleCallback onAbilityBackground.');
}
};
```
......@@ -221,7 +221,7 @@ onAbilityContinue(ability: UIAbility): void;
```ts
let abilityLifecycleCallback = {
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue.");
console.log('AbilityLifecycleCallback onAbilityContinue.');
}
};
```
......@@ -232,52 +232,52 @@ let abilityLifecycleCallback = {
MyFirstAbility.ts
```ts
import AbilityLifecycleCallback from "@ohos.app.ability.AbilityLifecycleCallback";
import AbilityStage from "@ohos.app.ability.AbilityStage";
import AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback';
import AbilityStage from '@ohos.app.ability.AbilityStage';
import UIAbility from '@ohos.app.ability.UIAbility';
// 声明ability生命周期回调,需配置所有回调后才可以在applicationContext注册
let abilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate.");
console.log('AbilityLifecycleCallback onAbilityCreate.');
},
onWindowStageCreate(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageCreate.");
console.log('AbilityLifecycleCallback onWindowStageCreate.');
},
onWindowStageActive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageActive.");
console.log('AbilityLifecycleCallback onWindowStageActive.');
},
onWindowStageInactive(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageInactive.");
console.log('AbilityLifecycleCallback onWindowStageInactive.');
},
onWindowStageDestroy(ability, windowStage){
console.log("AbilityLifecycleCallback onWindowStageDestroy.");
console.log('AbilityLifecycleCallback onWindowStageDestroy.');
},
onAbilityDestroy(ability){
console.log("AbilityLifecycleCallback onAbilityDestroy.");
console.log('AbilityLifecycleCallback onAbilityDestroy.');
},
onAbilityForeground(ability){
console.log("AbilityLifecycleCallback onAbilityForeground.");
console.log('AbilityLifecycleCallback onAbilityForeground.');
},
onAbilityBackground(ability){
console.log("AbilityLifecycleCallback onAbilityBackground.");
console.log('AbilityLifecycleCallback onAbilityBackground.');
},
onAbilityContinue(ability){
console.log("AbilityLifecycleCallback onAbilityContinue.");
console.log('AbilityLifecycleCallback onAbilityContinue.');
}
};
export default class MyFirstAbility extends UIAbility {
onCreate() {
console.log("MyAbilityStage onCreate");
console.log('MyAbilityStage onCreate');
// 1.通过context属性获取applicationContext
let applicationContext = this.context.getApplicationContext();
// 2.通过applicationContext注册监听应用内生命周期
try {
globalThis.lifecycleId = applicationContext.on("abilityLifecycle", abilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleId));
globalThis.lifecycleId = applicationContext.on('abilityLifecycle', abilityLifecycleCallback);
console.log('registerAbilityLifecycleCallback number: ' + JSON.stringify(lifecycleId));
} catch (paramError) {
console.log("error: " + paramError.code + " ," + paramError.message);
console.log('error: ' + paramError.code + ' ,' + paramError.message);
}
}
}
......@@ -285,17 +285,17 @@ export default class MyFirstAbility extends UIAbility {
MySecondAbility.ts
```ts
import UIAbility from "ohos.app.ability.UIAbility";
import UIAbility from 'ohos.app.ability.UIAbility';
export default class MySecondAbility extends UIAbility {
onDestroy() {
let applicationContext = this.context.getApplicationContext();
// 3.通过applicationContext注销监听应用内生命周期
applicationContext.off("abilityLifecycle", globalThis.lifecycleId, (error) => {
applicationContext.off('abilityLifecycle', globalThis.lifecycleId, (error) => {
if (error && error.code !== 0) {
console.log("unregisterAbilityLifecycleCallback fail, error: " + JSON.stringify(error));
console.log('unregisterAbilityLifecycleCallback fail, error: ' + JSON.stringify(error));
} else {
console.log("unregisterAbilityLifecycleCallback success.");
console.log('unregisterAbilityLifecycleCallback success.');
}
});
}
......
......@@ -64,7 +64,7 @@ const config = {
language: 'Zh-Hans', // 简体中文
colorMode: COLOR_MODE_LIGHT, // 浅色模式
direction: DIRECTION_VERTICAL, // 垂直方向
screenDensity: SCREEN_DENSITY_SDPI, // 屏幕分辨率为"sdpi"
screenDensity: SCREEN_DENSITY_SDPI, // 屏幕分辨率为'sdpi'
displayId: 1, // 应用在Id为1的物理屏上显示
hasPointerDevice: true, // 指针类型设备已连接
};
......@@ -72,9 +72,9 @@ const config = {
try {
abilityManager.updateConfiguration(config, (err) => {
if (err && err.code !== 0) {
console.log("updateConfiguration fail, err: " + JSON.stringify(err));
console.log('updateConfiguration fail, err: ' + JSON.stringify(err));
} else {
console.log("updateConfiguration success.");
console.log('updateConfiguration success.');
}
})
} catch (paramError) {
......@@ -122,7 +122,7 @@ const config = {
language: 'Zh-Hans', // 简体中文
colorMode: COLOR_MODE_LIGHT, // 浅色模式
direction: DIRECTION_VERTICAL, // 垂直方向
screenDensity: SCREEN_DENSITY_SDPI, // 屏幕分辨率为"sdpi"
screenDensity: SCREEN_DENSITY_SDPI, // 屏幕分辨率为'sdpi'
displayId: 1, // 应用在Id为1的物理屏上显示
hasPointerDevice: true, // 指针类型设备已连接
};
......@@ -171,9 +171,9 @@ import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.getAbilityRunningInfos((err, data) => {
if (err && err.code !== 0) {
console.log("getAbilityRunningInfos fail, error: " + JSON.stringify(err));
console.log('getAbilityRunningInfos fail, error: ' + JSON.stringify(err));
} else {
console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data));
console.log('getAbilityRunningInfos success, data: ' + JSON.stringify(data));
}
});
} catch (paramError) {
......@@ -213,9 +213,9 @@ import abilityManager from '@ohos.app.ability.abilityManager';
try {
abilityManager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos success, data: " + JSON.stringify(data))
console.log('getAbilityRunningInfos success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getAbilityRunningInfos fail, err: " + JSON.stringify(err));
console.log('getAbilityRunningInfos fail, err: ' + JSON.stringify(err));
});
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code)
......@@ -258,9 +258,9 @@ let upperLimit = 10;
try {
abilityManager.getExtensionRunningInfos(upperLimit, (err, data) => {
if (err && err.code !== 0) {
console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err));
console.log('getExtensionRunningInfos fail, err: ' + JSON.stringify(err));
} else {
console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data));
console.log('getExtensionRunningInfos success, data: ' + JSON.stringify(data));
}
});
} catch (paramError) {
......@@ -308,9 +308,9 @@ let upperLimit = 10;
try {
abilityManager.getExtensionRunningInfos(upperLimit).then((data) => {
console.log("getExtensionRunningInfos success, data: " + JSON.stringify(data));
console.log('getExtensionRunningInfos success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getExtensionRunningInfos fail, err: " + JSON.stringify(err));
console.log('getExtensionRunningInfos fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log('error.code: ' + JSON.stringify(paramError.code)
......@@ -347,9 +347,9 @@ import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.getTopAbility((err, data) => {
if (err && err.code !== 0) {
console.log("getTopAbility fail, err: " + JSON.stringify(err));
console.log('getTopAbility fail, err: ' + JSON.stringify(err));
} else {
console.log("getTopAbility success, data: " + JSON.stringify(data));
console.log('getTopAbility success, data: ' + JSON.stringify(data));
}
});
```
......@@ -382,8 +382,8 @@ getTopAbility(): Promise\<ElementName>;
import abilityManager from '@ohos.app.ability.abilityManager';
abilityManager.getTopAbility().then((data) => {
console.log("getTopAbility success, data: " + JSON.stringify(data));
console.log('getTopAbility success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getTopAbility fail, err: " + JSON.stringify(err));
console.log('getTopAbility fail, err: ' + JSON.stringify(err));
})
```
\ No newline at end of file
......@@ -30,7 +30,7 @@ import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage.onCreate is called");
console.log('MyAbilityStage.onCreate is called');
}
}
```
......@@ -63,8 +63,8 @@ import AbilityStage from '@ohos.app.ability.AbilityStage';
class MyAbilityStage extends AbilityStage {
onAcceptWant(want) {
console.log("MyAbilityStage.onAcceptWant called");
return "com.example.test";
console.log('MyAbilityStage.onAcceptWant called');
return 'com.example.test';
}
}
```
......
......@@ -41,9 +41,9 @@ import appManager from '@ohos.app.ability.appManager';
appManager.isRunningInStabilityTest((err, flag) => {
if (err && err.code !== 0) {
console.log("isRunningInStabilityTest fail, err: " + JSON.stringify(err));
console.log('isRunningInStabilityTest fail, err: ' + JSON.stringify(err));
} else {
console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag));
console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
}
})
```
......@@ -77,9 +77,9 @@ static isRunningInStabilityTest(): Promise&lt;boolean&gt;
import appManager from '@ohos.app.ability.appManager';
appManager.isRunningInStabilityTest().then((flag) => {
console.log("The result of isRunningInStabilityTest is:" + JSON.stringify(flag));
console.log('The result of isRunningInStabilityTest is:' + JSON.stringify(flag));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
console.log('error:' + JSON.stringify(error));
});
```
......@@ -112,9 +112,9 @@ isRamConstrainedDevice(): Promise\<boolean>;
import appManager from '@ohos.app.ability.appManager';
appManager.isRamConstrainedDevice().then((data) => {
console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data));
console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
console.log('error:' + JSON.stringify(error));
});
```
......@@ -147,9 +147,9 @@ import appManager from '@ohos.app.ability.appManager';
appManager.isRamConstrainedDevice((err, data) => {
if (err && err.code !== 0) {
console.log("isRamConstrainedDevice fail, err: " + JSON.stringify(err));
console.log('isRamConstrainedDevice fail, err: ' + JSON.stringify(err));
} else {
console.log("The result of isRamConstrainedDevice is:" + JSON.stringify(data));
console.log('The result of isRamConstrainedDevice is:' + JSON.stringify(data));
}
})
```
......@@ -182,9 +182,9 @@ getAppMemorySize(): Promise\<number>;
import appManager from '@ohos.app.ability.appManager';
appManager.getAppMemorySize().then((data) => {
console.log("The size of app memory is:" + JSON.stringify(data));
console.log('The size of app memory is:' + JSON.stringify(data));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
console.log('error:' + JSON.stringify(error));
});
```
......@@ -217,9 +217,9 @@ import appManager from '@ohos.app.ability.appManager';
appManager.getAppMemorySize((err, data) => {
if (err && err.code !== 0) {
console.log("getAppMemorySize fail, err: " + JSON.stringify(err));
console.log('getAppMemorySize fail, err: ' + JSON.stringify(err));
} else {
console.log("The size of app memory is:" + JSON.stringify(data));
console.log('The size of app memory is:' + JSON.stringify(data));
}
})
```
......@@ -254,9 +254,9 @@ getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>;
import appManager from '@ohos.app.ability.appManager';
appManager.getRunningProcessInformation().then((data) => {
console.log("The running process information is:" + JSON.stringify(data));
console.log('The running process information is:' + JSON.stringify(data));
}).catch((error) => {
console.log("error:" + JSON.stringify(error));
console.log('error:' + JSON.stringify(error));
});
```
......@@ -291,16 +291,16 @@ import appManager from '@ohos.app.ability.appManager';
appManager.getRunningProcessInformation((err, data) => {
if (err && err.code !== 0) {
console.log("getRunningProcessInformation fail, err: " + JSON.stringify(err));
console.log('getRunningProcessInformation fail, err: ' + JSON.stringify(err));
} else {
console.log("The process running information is:" + JSON.stringify(data));
console.log('The process running information is:' + JSON.stringify(data));
}
})
```
## appManager.on
on(type: "applicationState", observer: ApplicationStateObserver): number;
on(type: 'applicationState', observer: ApplicationStateObserver): number;
注册全部应用程序的状态观测器。
......@@ -314,7 +314,7 @@ on(type: "applicationState", observer: ApplicationStateObserver): number;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| type | string | 是 | 调用接口类型,固定填'applicationState'字符串。 |
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | 是 | 应用状态观测器,用于观测应用的生命周期变化。 |
**返回值:**
......@@ -363,7 +363,7 @@ try {
## appManager.on
on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
注册指定应用程序的状态观测器。
......@@ -377,7 +377,7 @@ on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList:
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| type | string | 是 | 调用接口类型,固定填'applicationState'字符串。 |
| observer | [ApplicationStateObserver](./js-apis-inner-application-applicationStateObserver.md) | 是 | 应用状态观测器,用于观测应用的生命周期变化。 |
| bundleNameList | `Array<string>` | 是 | 表示需要注册监听的bundleName数组。最大值128。 |
......@@ -419,7 +419,7 @@ let applicationStateObserver = {
}
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
const observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList);
const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
......@@ -428,7 +428,7 @@ try {
## appManager.off
off(type: "applicationState", observerId: number, callback: AsyncCallback\<void>): void;
off(type: 'applicationState', observerId: number, callback: AsyncCallback\<void>): void;
取消注册应用程序状态观测器。
......@@ -442,7 +442,7 @@ off(type: "applicationState", observerId: number, callback: AsyncCallback\<void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| type | string | 是 | 调用接口类型,固定填'applicationState'字符串。 |
| observerId | number | 是 | 表示观测器的编号代码。 |
| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
......@@ -481,7 +481,7 @@ let applicationStateObserver = {
}
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList);
observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
......@@ -490,13 +490,13 @@ try {
// 2.注销应用状态监听器
function unregisterApplicationStateObserverCallback(err) {
if (err && err.code !== 0) {
console.log("unregisterApplicationStateObserverCallback fail, err: " + JSON.stringify(err));
console.log('unregisterApplicationStateObserverCallback fail, err: ' + JSON.stringify(err));
} else {
console.log("unregisterApplicationStateObserverCallback success.");
console.log('unregisterApplicationStateObserverCallback success.');
}
}
try {
appManager.off("applicationState", observerId, unregisterApplicationStateObserverCallback);
appManager.off('applicationState', observerId, unregisterApplicationStateObserverCallback);
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
......@@ -504,7 +504,7 @@ try {
## appManager.off
off(type: "applicationState", observerId: number): Promise\<void>;
off(type: 'applicationState', observerId: number): Promise\<void>;
取消注册应用程序状态观测器。
......@@ -518,7 +518,7 @@ off(type: "applicationState", observerId: number): Promise\<void>;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| type | string | 是 | 调用接口类型,固定填'applicationState'字符串。 |
| observerId | number | 是 | 表示观测器的编号代码。 |
**返回值:**
......@@ -562,7 +562,7 @@ let applicationStateObserver = {
}
let bundleNameList = ['bundleName1', 'bundleName2'];
try {
observerId = appManager.on("applicationState", applicationStateObserver, bundleNameList);
observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList);
console.log(`[appManager] observerCode: ${observerId}`);
} catch (paramError) {
console.log(`[appManager] error: ${paramError.code}, ${paramError.message} `);
......@@ -570,10 +570,10 @@ try {
// 2.注销应用状态监听器
try {
appManager.off("applicationState", observerId).then((data) => {
console.log("unregisterApplicationStateObserver success, data: " + JSON.stringify(data));
appManager.off('applicationState', observerId).then((data) => {
console.log('unregisterApplicationStateObserver success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("unregisterApplicationStateObserver fail, err: " + JSON.stringify(err));
console.log('unregisterApplicationStateObserver fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log('error: ' + paramError.code + ', ' + paramError.message);
......@@ -613,15 +613,15 @@ import appManager from '@ohos.app.ability.appManager';
function getForegroundApplicationsCallback(err, data) {
if (err && err.code !== 0) {
console.log("getForegroundApplicationsCallback fail, err: " + JSON.stringify(err));
console.log('getForegroundApplicationsCallback fail, err: ' + JSON.stringify(err));
} else {
console.log("getForegroundApplicationsCallback success, data: " + JSON.stringify(data));
console.log('getForegroundApplicationsCallback success, data: ' + JSON.stringify(data));
}
}
try {
appManager.getForegroundApplications(getForegroundApplicationsCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -657,9 +657,9 @@ getForegroundApplications(): Promise\<Array\<AppStateData>>;
import appManager from '@ohos.app.ability.appManager';
appManager.getForegroundApplications().then((data) => {
console.log("getForegroundApplications success, data: " + JSON.stringify(data));
console.log('getForegroundApplications success, data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getForegroundApplications fail, err: " + JSON.stringify(err));
console.log('getForegroundApplications fail, err: ' + JSON.stringify(err));
})
```
......@@ -699,12 +699,12 @@ let bundleName = 'bundleName';
let accountId = 0;
try {
appManager.killProcessWithAccount(bundleName, accountId).then(() => {
console.log("killProcessWithAccount success");
console.log('killProcessWithAccount success');
}).catch((err) => {
console.log("killProcessWithAccount fail, err: " + JSON.stringify(err));
console.error('killProcessWithAccount fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.error('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -746,9 +746,9 @@ let bundleName = 'bundleName';
let accountId = 0;
function killProcessWithAccountCallback(err, data) {
if (err && err.code !== 0) {
console.log("killProcessWithAccountCallback fail, err: " + JSON.stringify(err));
console.log('killProcessWithAccountCallback fail, err: ' + JSON.stringify(err));
} else {
console.log("killProcessWithAccountCallback success.");
console.log('killProcessWithAccountCallback success.');
}
}
appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
......@@ -789,15 +789,15 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
function killProcessesByBundleNameCallback(err, data) {
if (err && err.code !== 0) {
console.log("killProcessesByBundleNameCallback fail, err: " + JSON.stringify(err));
console.log('killProcessesByBundleNameCallback fail, err: ' + JSON.stringify(err));
} else {
console.log("killProcessesByBundleNameCallback success.");
console.log('killProcessesByBundleNameCallback success.');
}
}
try {
appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -841,12 +841,12 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
try {
appManager.killProcessesByBundleName(bundleName).then((data) => {
console.log("killProcessesByBundleName success.");
console.log('killProcessesByBundleName success.');
}).catch((err) => {
console.log("killProcessesByBundleName fail, err: " + JSON.stringify(err));
console.log('killProcessesByBundleName fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -885,15 +885,15 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
function clearUpApplicationDataCallback(err, data) {
if (err && err.code !== 0) {
console.log("clearUpApplicationDataCallback fail, err: " + JSON.stringify(err));
console.log('clearUpApplicationDataCallback fail, err: ' + JSON.stringify(err));
} else {
console.log("clearUpApplicationDataCallback success.");
console.log('clearUpApplicationDataCallback success.');
}
}
try {
appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -937,12 +937,12 @@ import appManager from '@ohos.app.ability.appManager';
let bundleName = 'bundleName';
try {
appManager.clearUpApplicationData(bundleName).then((data) => {
console.log("clearUpApplicationData success.");
console.log('clearUpApplicationData success.');
}).catch((err) => {
console.log("clearUpApplicationData fail, err: " + JSON.stringify(err));
console.log('clearUpApplicationData fail, err: ' + JSON.stringify(err));
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......
......@@ -97,15 +97,15 @@ import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
console.log('onUnhandledException, errorMsg: ', errorMsg);
appRecovery.restartApp();
}
};
try {
errorManager.on("error", observer);
errorManager.on('error', observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -131,14 +131,14 @@ import errorManager from '@ohos.app.ability.errorManager';
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
console.log('onUnhandledException, errorMsg: ', errorMsg);
appRecovery.saveAppState();
}
};
try {
errorManager.on("error", observer);
errorManager.on('error', observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -10,7 +10,7 @@ Common模块将二级模块API组织在一起方便开发者进行导出。
## 导入模块
```ts
import common from '@ohos.app.ability.common'
import common from '@ohos.app.ability.common';
```
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityBase
......@@ -32,7 +32,7 @@ import common from '@ohos.app.ability.common'
**示例:**
```ts
import common from '@ohos.app.ability.common'
import common from '@ohos.app.ability.common';
let uiAbilityContext: common.UIAbilityContext;
let abilityStageContext: common.AbilityStageContext;
......
......@@ -28,7 +28,7 @@ export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
let envCallback = {
onConfigurationUpdated(config) {
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`)
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
let language = config.language;
let colorMode = config.colorMode;
let direction = config.direction;
......@@ -39,10 +39,10 @@ export default class EntryAbility extends UIAbility {
};
try {
let applicationContext = this.context.getApplicationContext();
let callbackId = applicationContext.on("environment", envCallback);
console.log("callbackId: " + callbackId);
let callbackId = applicationContext.on('environment', envCallback);
console.log('callbackId: ' + callbackId);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
}
}
......
......@@ -47,9 +47,9 @@ import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant';
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| SCREEN_DENSITY_NOT_SET | 0 | 未设置屏幕分辨率。 |
| SCREEN_DENSITY_SDPI | 120 | 屏幕分辨率为"sdpi"。 |
| SCREEN_DENSITY_MDPI | 160 | 屏幕分辨率为"mdpi"。 |
| SCREEN_DENSITY_LDPI | 240 | 屏幕分辨率为"ldpi"。 |
| SCREEN_DENSITY_XLDPI | 320 | 屏幕分辨率为"xldpi"。 |
| SCREEN_DENSITY_XXLDPI | 480 | 屏幕分辨率为"xxldpi"。 |
| SCREEN_DENSITY_XXXLDPI | 640 | 屏幕分辨率为"xxxldpi"。 |
| SCREEN_DENSITY_SDPI | 120 | 屏幕分辨率为'sdpi'。 |
| SCREEN_DENSITY_MDPI | 160 | 屏幕分辨率为'mdpi'。 |
| SCREEN_DENSITY_LDPI | 240 | 屏幕分辨率为'ldpi'。 |
| SCREEN_DENSITY_XLDPI | 320 | 屏幕分辨率为'xldpi'。 |
| SCREEN_DENSITY_XXLDPI | 480 | 屏幕分辨率为'xxldpi'。 |
| SCREEN_DENSITY_XXXLDPI | 640 | 屏幕分辨率为'xxxldpi'。 |
......@@ -36,10 +36,10 @@ getId(uri: string): number
```ts
try {
let id = dataUriUtils.getId("com.example.dataUriUtils/1221")
console.info('get id: ' + id)
let id = dataUriUtils.getId('com.example.dataUriUtils/1221');
console.info('get id: ' + id);
} catch(err) {
console.error('get id err ,check the uri' + err)
console.error('get id err ,check the uri' + err);
}
```
......@@ -72,12 +72,12 @@ attachId(uri: string, id: number): string
let id = 1122;
try {
let uri = dataUriUtils.attachId(
"com.example.dataUriUtils",
'com.example.dataUriUtils',
id,
)
console.info('attachId the uri is: ' + uri)
);
console.info('attachId the uri is: ' + uri);
} catch (err) {
console.error('get id err ,check the uri' + err)
console.error('get id err ,check the uri' + err);
}
```
......@@ -108,10 +108,10 @@ deleteId(uri: string): string
```ts
try {
let uri = dataUriUtils.deleteId("com.example.dataUriUtils/1221")
console.info('delete id with the uri is: ' + uri)
let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221');
console.info('delete id with the uri is: ' + uri);
} catch(err) {
console.error('delete uri err, check the input uri' + err)
console.error('delete uri err, check the input uri' + err);
}
```
......@@ -146,11 +146,11 @@ updateId(uri: string, id: number): string
try {
let id = 1122;
let uri = dataUriUtils.updateId(
"com.example.dataUriUtils/1221",
'com.example.dataUriUtils/1221',
id
)
);
} catch (err) {
console.error('delete uri err, check the input uri' + err)
console.error('delete uri err, check the input uri' + err);
}
```
......@@ -49,9 +49,9 @@ getRequestInfo(want: Want): RequestInfo
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestInfo = dialogRequest.getRequestInfo(want)
var requestInfo = dialogRequest.getRequestInfo(want);
} catch(err) {
console.error('getRequestInfo err= ' + JSON.stringify(err))
console.error('getRequestInfo err= ' + JSON.stringify(err));
}
}
......@@ -104,9 +104,9 @@ getRequestCallback(want: Want): RequestCallback
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestCallback = dialogRequest.getRequestCallback(want)
var requestCallback = dialogRequest.getRequestCallback(want);
} catch(err) {
console.error('getRequestInfo err= ' + JSON.stringify(err))
console.error('getRequestInfo err= ' + JSON.stringify(err));
}
}
......@@ -145,7 +145,7 @@ getRequestCallback(want: Want): RequestCallback
onRequest(want, startId) {
console.info(TAG, `onRequest, want: ${want.abilityName}`);
try {
var requestInfo = dialogRequest.getRequestInfo(want)
var requestInfo = dialogRequest.getRequestInfo(want);
window.bindDialogTarget(requestInfo, () => {
console.info('Dialog Window Need Destroy.');
}, (err) => {
......@@ -156,7 +156,7 @@ getRequestCallback(want: Want): RequestCallback
console.info('Succeeded in binding dialog target.');
});
} catch(err) {
console.error('getRequestInfo err= ' + JSON.stringify(err))
console.error('getRequestInfo err= ' + JSON.stringify(err));
}
}
......@@ -243,7 +243,7 @@ setRequestResult(result: RequestResult): void;
};
requestCallback.setRequestResult(myResult);
} catch(err) {
console.error('getRequestInfo err= ' + JSON.stringify(err))
console.error('getRequestInfo err= ' + JSON.stringify(err));
}
}
......
......@@ -11,7 +11,7 @@ EnvironmentCallback模块提供应用上下文ApplicationContext对系统环境
## 导入模块
```ts
import EnvironmentCallback from "@ohos.app.ability.EnvironmentCallback";
import EnvironmentCallback from '@ohos.app.ability.EnvironmentCallback';
```
......@@ -33,29 +33,29 @@ onConfigurationUpdated(config: Configuration): void;
```ts
import UIAbility from "@ohos.app.ability.Ability";
import UIAbility from '@ohos.app.ability.Ability';
let callbackId;
export default class MyAbility extends UIAbility {
onCreate() {
console.log("MyAbility onCreate")
console.log('MyAbility onCreate');
globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = {
onConfigurationUpdated(config){
console.log("onConfigurationUpdated config:" + JSON.stringify(config));
console.log('onConfigurationUpdated config:' + JSON.stringify(config));
}
}
// 1.获取applicationContext
let applicationContext = globalThis.applicationContext;
// 2.通过applicationContext注册监听应用内生命周期
callbackId = applicationContext.registerEnvironmentCallback(EnvironmentCallback);
console.log("registerEnvironmentCallback number: " + JSON.stringify(callbackId));
console.log('registerEnvironmentCallback number: ' + JSON.stringify(callbackId));
}
onDestroy() {
let applicationContext = globalThis.applicationContext;
applicationContext.unregisterEnvironmentCallback(callbackId, (error, data) => {
console.log("unregisterEnvironmentCallback success, err: " + JSON.stringify(error));
console.log('unregisterEnvironmentCallback success, err: ' + JSON.stringify(error));
});
}
}
......
......@@ -8,12 +8,12 @@ ErrorManager模块提供对错误观察器的注册和注销的能力。使用
## 导入模块
```ts
import errorManager from '@ohos.app.ability.errorManager'
import errorManager from '@ohos.app.ability.errorManager';
```
## ErrorManager.on
on(type: "error", observer: ErrorObserver): number;
on(type: 'error', observer: ErrorObserver): number;
注册错误观测器。
......@@ -23,7 +23,7 @@ on(type: "error", observer: ErrorObserver): number;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 填写"error",表示错误观察器。 |
| type | string | 是 | 填写'error',表示错误观察器。 |
| observer | [ErrorObserver](./js-apis-inner-application-errorObserver.md) | 是 | 错误观察器。 |
**返回值:**
......@@ -37,20 +37,20 @@ on(type: "error", observer: ErrorObserver): number;
```ts
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
console.log('onUnhandledException, errorMsg: ', errorMsg);
}
}
let observerId = -1;
try {
observerId = errorManager.on("error", observer);
observerId = errorManager.on('error', observer);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
## ErrorManager.off
off(type: "error", observerId: number, callback: AsyncCallback\<void>): void;
off(type: 'error', observerId: number, callback: AsyncCallback\<void>): void;
注销错误观测器。
......@@ -60,7 +60,7 @@ off(type: "error", observerId: number, callback: AsyncCallback\<void>): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 填写"error",表示错误观察器。 |
| type | string | 是 | 填写'error',表示错误观察器。 |
| observerId | number | 是 | 由on方法返回的观察器的index值。 |
| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法。 |
......@@ -75,15 +75,15 @@ function unregisterErrorObserverCallback(err) {
}
}
try {
errorManager.off("error", observerId, unregisterErrorObserverCallback);
errorManager.off('error', observerId, unregisterErrorObserverCallback);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
## ErrorManager.off
off(type: "error", observerId: number): Promise\<void>;
off(type: 'error', observerId: number): Promise\<void>;
注销错误观测器。
......@@ -93,7 +93,7 @@ off(type: "error", observerId: number): Promise\<void>;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 填写"error",表示错误观察器。 |
| type | string | 是 | 填写'error',表示错误观察器。 |
| observerId | number | 是 | 由on方法返回的观察器的index值。 |
**返回值:**
......@@ -107,7 +107,7 @@ off(type: "error", observerId: number): Promise\<void>;
```ts
let observerId = 100;
try {
errorManager.off("error", observerId)
errorManager.off('error', observerId)
.then((data) => {
console.log('----------- unregisterErrorObserver success ----------', data);
})
......@@ -115,7 +115,7 @@ try {
console.log('----------- unregisterErrorObserver fail ----------', err);
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -18,7 +18,7 @@ ohos.permission.MANAGE_MISSIONS
## missionManager.on
on(type:"mission", listener: MissionListener): number;
on(type:'mission', listener: MissionListener): number;
注册系统任务状态监听器。
......@@ -47,52 +47,52 @@ import missionManager from '@ohos.app.ability.missionManager';
import UIAbility from '@ohos.app.ability.UIAbility';
let listener = {
onMissionCreated: function (mission) {console.log("--------onMissionCreated-------")},
onMissionDestroyed: function (mission) {console.log("--------onMissionDestroyed-------")},
onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")},
onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")},
onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")},
onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")},
onMissionLabelUpdated: function (mission) {console.log("--------onMissionLabelUpdated-------")}
onMissionCreated: function (mission) {console.log('--------onMissionCreated-------')},
onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------')},
onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------')},
onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------')},
onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------')},
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------')},
onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------')}
};
let listenerId = -1;
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log("[Demo] EntryAbility onCreate");
console.log('[Demo] EntryAbility onCreate');
globalThis.abilityWant = want;
globalThis.context = this.context;
}
onDestroy() {
try {
if (listenerId != -1) {
missionManager.off("mission", listenerId).catch(function (err) {
if (listenerId !== -1) {
missionManager.off('mission', listenerId).catch(function (err) {
console.log(err);
});
}
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
console.log("[Demo] EntryAbility onDestroy")
console.log('[Demo] EntryAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] EntryAbility onWindowStageCreate")
console.log('[Demo] EntryAbility onWindowStageCreate');
try {
listenerId = missionManager.on("mission", listener);
listenerId = missionManager.on('mission', listener);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
windowStage.loadContent("pages/index", (err, data) => {
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
});
if (globalThis.flag) {
......@@ -105,7 +105,7 @@ export default class EntryAbility extends UIAbility {
## missionManager.off
off(type: "mission", listenerId: number, callback: AsyncCallback&lt;void&gt;): void;
off(type: 'mission', listenerId: number, callback: AsyncCallback&lt;void&gt;): void;
解注册任务状态监听器。
......@@ -129,52 +129,52 @@ import missionManager from '@ohos.app.ability.missionManager';
import UIAbility from '@ohos.app.ability.UIAbility';
let listener = {
onMissionCreated: function (mission) {console.log("--------onMissionCreated-------")},
onMissionDestroyed: function (mission) {console.log("--------onMissionDestroyed-------")},
onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")},
onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")},
onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")},
onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")},
onMissionLabelUpdated: function (mission) {console.log("--------onMissionLabelUpdated-------")}
onMissionCreated: function (mission) {console.log('--------onMissionCreated-------')},
onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------')},
onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------')},
onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------')},
onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------')},
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------')},
onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------')}
};
let listenerId = -1;
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log("[Demo] EntryAbility onCreate")
console.log('[Demo] EntryAbility onCreate');
globalThis.abilityWant = want;
globalThis.context = this.context;
}
onDestroy() {
try {
if (listenerId != -1) {
missionManager.off("mission", listenerId, (err) => {
if (listenerId !== -1) {
missionManager.off('mission', listenerId, (err) => {
console.log(err);
});
}
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
console.log("[Demo] EntryAbility onDestroy")
console.log('[Demo] EntryAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] EntryAbility onWindowStageCreate")
console.log('[Demo] EntryAbility onWindowStageCreate');
try {
listenerId = missionManager.on("mission", listener);
listenerId = missionManager.on('mission', listener);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
windowStage.loadContent("pages/index", (err, data) => {
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
});
if (globalThis.flag) {
......@@ -187,7 +187,7 @@ export default class EntryAbility extends UIAbility {
## missionManager.off
off(type: "mission", listenerId: number): Promise&lt;void&gt;;
off(type: 'mission', listenerId: number): Promise&lt;void&gt;;
解注册任务状态监听,以promise方式返回执行结果。
......@@ -216,52 +216,52 @@ import missionManager from '@ohos.app.ability.missionManager';
import UIAbility from '@ohos.app.ability.UIAbility';
let listener = {
onMissionCreated: function (mission) {console.log("--------onMissionCreated-------")},
onMissionDestroyed: function (mission) {console.log("--------onMissionDestroyed-------")},
onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")},
onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")},
onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")},
onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")},
onMissionLabelUpdated: function (mission) {console.log("--------onMissionLabelUpdated-------")}
onMissionCreated: function (mission) {console.log('--------onMissionCreated-------')},
onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------')},
onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------')},
onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------')},
onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------')},
onMissionClosed: function (mission) {console.log('--------onMissionClosed-------')},
onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------')}
};
let listenerId = -1;
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
console.log("[Demo] EntryAbility onCreate")
console.log('[Demo] EntryAbility onCreate');
globalThis.abilityWant = want;
globalThis.context = this.context;
}
onDestroy() {
try {
if (listenerId != -1) {
missionManager.off("mission", listenerId).catch(function (err) {
if (listenerId !== -1) {
missionManager.off('mission', listenerId).catch(function (err) {
console.log(err);
});
}
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
console.log("[Demo] EntryAbility onDestroy")
console.log('[Demo] EntryAbility onDestroy');
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[Demo] EntryAbility onWindowStageCreate")
console.log('[Demo] EntryAbility onWindowStageCreate');
try {
listenerId = missionManager.on("mission", listener);
listenerId = missionManager.on('mission', listener);
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
windowStage.loadContent("pages/index", (err, data) => {
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
});
if (globalThis.flag) {
......@@ -299,26 +299,26 @@ getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback&lt;M
let testMissionId = 1;
try {
let allMissions=await missionManager.getMissionInfos("",10).catch(function(err){console.log(err);});
let allMissions=await missionManager.getMissionInfos('',10).catch(function(err){console.log(err);});
if (allMissions && allMissions.length > 0) {
testMissionId = allMissions[0].missionId;
}
missionManager.getMissionInfo("", testMissionId, (error, mission) => {
missionManager.getMissionInfo('', testMissionId, (error, mission) => {
if (error) {
console.log("getMissionInfo failed, error.code:" + JSON.stringify(error.code) +
"error.message:" + JSON.stringify(error.message));
console.log('getMissionInfo failed, error.code:' + JSON.stringify(error.code) +
'error.message:' + JSON.stringify(error.message));
} else {
console.log("mission.missionId = " + mission.missionId);
console.log("mission.runningState = " + mission.runningState);
console.log("mission.lockedState = " + mission.lockedState);
console.log("mission.timestamp = " + mission.timestamp);
console.log("mission.label = " + mission.label);
console.log("mission.iconPath = " + mission.iconPath);
console.log('mission.missionId = ' + mission.missionId);
console.log('mission.runningState = ' + mission.runningState);
console.log('mission.lockedState = ' + mission.lockedState);
console.log('mission.timestamp = ' + mission.timestamp);
console.log('mission.label = ' + mission.label);
console.log('mission.iconPath = ' + mission.iconPath);
}
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -355,7 +355,7 @@ import missionManager from '@ohos.app.ability.missionManager';
let testMissionId = 1;
try {
missionManager.getMissionInfo("", testMissionId).then((data) => {
missionManager.getMissionInfo('', testMissionId).then((data) => {
console.info('getMissionInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getMissionInfo failed. Cause: ' + error.message);
......@@ -391,17 +391,17 @@ getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback&lt;Arr
import missionManager from '@ohos.app.ability.missionManager';
try {
missionManager.getMissionInfos("", 10, (error, missions) => {
missionManager.getMissionInfos('', 10, (error, missions) => {
if (error) {
console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
"error.message:" + JSON.stringify(error.message));
console.log('getMissionInfos failed, error.code:' + JSON.stringify(error.code) +
'error.message:' + JSON.stringify(error.message));
} else {
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
console.log('size = ' + missions.length);
console.log('missions = ' + JSON.stringify(missions));
}
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -437,7 +437,7 @@ getMissionInfos(deviceId: string, numMax: number): Promise&lt;Array&lt;MissionIn
import missionManager from '@ohos.app.ability.missionManager';
try {
missionManager.getMissionInfos("", 10).then((data) => {
missionManager.getMissionInfos('', 10).then((data) => {
console.info('getMissionInfos successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getMissionInfos failed. Cause: ' + error.message);
......@@ -473,7 +473,7 @@ import missionManager from '@ohos.app.ability.missionManager';
let testMissionId = 2;
try {
missionManager.getMissionSnapShot("", testMissionId, (err, data) => {
missionManager.getMissionSnapShot('', testMissionId, (err, data) => {
if (err) {
console.error('getMissionSnapShot failed:' + err.message);
} else {
......@@ -516,7 +516,7 @@ import missionManager from '@ohos.app.ability.missionManager';
let testMissionId = 2;
try {
missionManager.getMissionSnapShot("", testMissionId).then((data) => {
missionManager.getMissionSnapShot('', testMissionId).then((data) => {
console.info('getMissionSnapShot successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getMissionSnapShot failed. Cause: ' + error.message);
......@@ -552,7 +552,7 @@ import missionManager from '@ohos.app.ability.missionManager';
let testMissionId = 2;
try {
missionManager.getLowResolutionMissionSnapShot("", testMissionId, (err, data) => {
missionManager.getLowResolutionMissionSnapShot('', testMissionId, (err, data) => {
if (err) {
console.error('getLowResolutionMissionSnapShot failed:' + err.message);
} else {
......@@ -596,7 +596,7 @@ import missionManager from '@ohos.app.ability.missionManager';
let testMissionId = 2;
try {
missionManager.getLowResolutionMissionSnapShot("", testMissionId).then((data) => {
missionManager.getLowResolutionMissionSnapShot('', testMissionId).then((data) => {
console.info('getLowResolutionMissionSnapShot successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getLowResolutionMissionSnapShot failed. Cause: ' + error.message);
......
......@@ -68,16 +68,16 @@ applyQuickFix(hapModuleQuickFixFiles: Array\<string>, callback: AsyncCallback\<v
```ts
try {
let hapModuleQuickFixFiles = ["/data/storage/el2/base/entry.hqf"]
let hapModuleQuickFixFiles = ['/data/storage/el2/base/entry.hqf'];
quickFixManager.applyQuickFix(hapModuleQuickFixFiles, (error) => {
if (error) {
console.info( `applyQuickFix failed with error + ${error}`)
console.info( `applyQuickFix failed with error + ${error}`);
} else {
console.info( 'applyQuickFix success')
console.info( 'applyQuickFix success');
}
})
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -108,15 +108,15 @@ applyQuickFix(hapModuleQuickFixFiles: Array\<string>): Promise\<void>;
**示例:**
```ts
let hapModuleQuickFixFiles = ["/data/storage/el2/base/entry.hqf"]
let hapModuleQuickFixFiles = ['/data/storage/el2/base/entry.hqf'];
try {
quickFixManager.applyQuickFix(hapModuleQuickFixFiles).then(() => {
console.info('applyQuickFix success')
console.info('applyQuickFix success');
}).catch((error) => {
console.info(`applyQuickFix err: + ${error}`)
})
console.info(`applyQuickFix err: + ${error}`);
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -143,16 +143,16 @@ getApplicationQuickFixInfo(bundleName: string, callback: AsyncCallback\<Applicat
```ts
try {
let bundleName = "bundleName"
let bundleName = 'bundleName';
quickFixManager.getApplicationQuickFixInfo(bundleName, (error, data) => {
if (error) {
console.info(`getApplicationQuickFixInfo error: + ${error}`)
console.info(`getApplicationQuickFixInfo error: + ${error}`);
} else {
console.info(`getApplicationQuickFixInfo success: + ${data}`)
console.info(`getApplicationQuickFixInfo success: + ${data}`);
}
})
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -184,13 +184,13 @@ getApplicationQuickFixInfo(bundleName: string): Promise\<ApplicationQuickFixInfo
```ts
try {
let bundleName = "bundleName"
let bundleName = 'bundleName';
quickFixManager.getApplicationQuickFixInfo(bundleName).then((data) => {
console.info(`getApplicationQuickFixInfo success: + ${data}`)
console.info(`getApplicationQuickFixInfo success: + ${data}`);
}).catch((error) => {
console.info(`getApplicationQuickFixInfo err: + ${error}`)
})
console.info(`getApplicationQuickFixInfo err: + ${error}`);
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
\ No newline at end of file
......@@ -129,7 +129,7 @@ Extension生命周期回调,如果是connectAbility拉起的服务,会在onC
**示例:**
```ts
import rpc from '@ohos.rpc'
import rpc from '@ohos.rpc';
class StubTest extends rpc.RemoteObject{
constructor(des) {
super(des);
......@@ -140,7 +140,7 @@ Extension生命周期回调,如果是connectAbility拉起的服务,会在onC
class ServiceExt extends ServiceExtension {
onConnect(want) {
console.log('onConnect , want:' + want.abilityName);
return new StubTest("test");
return new StubTest('test');
}
}
```
......@@ -246,7 +246,7 @@ onDump(params: Array\<string>): Array\<string>;
class ServiceExt extends ServiceExtension {
onDump(params) {
console.log('dump, params:' + JSON.stringify(params));
return ["params"]
return ['params'];
}
}
```
......
......@@ -31,14 +31,14 @@ import StartOptions from '@ohos.app.ability.StartOptions';
import missionManager from '@ohos.app.ability.missionManager';
try {
missionManager.getMissionInfos("", 10, (error, missions) => {
missionManager.getMissionInfos('', 10, (error, missions) => {
if (error.code) {
console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code) +
"error.message:" + JSON.stringify(error.message));
console.log('getMissionInfos failed, error.code:' + JSON.stringify(error.code) +
'error.message:' + JSON.stringify(error.message));
return;
}
console.log("size = " + missions.length);
console.log("missions = " + JSON.stringify(missions));
console.log('size = ' + missions.length);
console.log('missions = ' + JSON.stringify(missions));
let id = missions[0].missionId;
let startOptions = {
......@@ -46,10 +46,10 @@ import StartOptions from '@ohos.app.ability.StartOptions';
displayId: 0
};
missionManager.moveMissionToFront(id, startOptions).then(() => {
console.log("moveMissionToFront is called ");
console.log('moveMissionToFront is called ');
});
});
} catch (paramError) {
console.log("error: " + paramError.code + ", " + paramError.message);
console.log('error: ' + paramError.code + ', ' + paramError.message);
}
```
......@@ -202,11 +202,11 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
**示例:**
```ts
import AbilityConstant from "@ohos.app.ability.AbilityConstant"
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
onContinue(wantParams) {
console.log('onContinue');
wantParams["myData"] = "my1234567";
wantParams['myData'] = 'my1234567';
return AbilityConstant.OnContinueResult.AGREE;
}
}
......@@ -259,7 +259,7 @@ onDump(params: Array\<string>): Array\<string>;
class MyUIAbility extends UIAbility {
onDump(params) {
console.log('dump, params:' + JSON.stringify(params));
return ["params"]
return ['params'];
}
}
```
......@@ -289,12 +289,12 @@ onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: any})
**示例:**
```ts
import AbilityConstant from '@ohos.app.ability.AbilityConstant'
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
class MyUIAbility extends UIAbility {
onSaveState(reason, wantParam) {
console.log('onSaveState');
wantParam["myData"] = "my1234567";
wantParam['myData'] = 'my1234567';
return AbilityConstant.OnSaveResult.RECOVERY_AGREE;
}
}
......@@ -339,8 +339,8 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
```ts
class MyMessageAble{ // 自定义的Sequenceable数据结构
name:""
str:""
name:''
str:''
num: 1
constructor(name, str) {
this.name = name;
......@@ -364,12 +364,12 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "MainUIAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'MainUIAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
let msg = new MyMessageAble("msg", "world"); // 参考Sequenceable数据定义
let msg = new MyMessageAble('msg', 'world'); // 参考Sequenceable数据定义
caller.call(method, msg)
.then(() => {
console.log('Caller call() called');
......@@ -420,8 +420,8 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa
```ts
class MyMessageAble{
name:""
str:""
name:''
str:''
num: 1
constructor(name, str) {
this.name = name;
......@@ -445,16 +445,16 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa
export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "MainUIAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'MainUIAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
let msg = new MyMessageAble(1, "world");
let msg = new MyMessageAble(1, 'world');
caller.callWithResult(method, msg)
.then((data) => {
console.log('Caller callWithResult() called');
let retmsg = new MyMessageAble(0, "");
let retmsg = new MyMessageAble(0, '');
data.readSequenceable(retmsg);
})
.catch((callErr) => {
......@@ -494,9 +494,9 @@ release(): void;
export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "MainUIAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'MainUIAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
try {
......@@ -534,9 +534,9 @@ release(): void;
export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "MainUIAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'MainUIAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
try {
......@@ -557,7 +557,7 @@ release(): void;
## Caller.on
on(type: "release", callback: OnReleaseCallback): void;
on(type: 'release', callback: OnReleaseCallback): void;
注册通用组件服务端Stub(桩)断开监听通知。
......@@ -585,13 +585,13 @@ release(): void;
export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "MainUIAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'MainUIAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
try {
caller.on("release", (str) => {
caller.on('release', (str) => {
console.log(' Caller OnRelease CallBack is called ' + str);
});
} catch (error) {
......@@ -608,7 +608,7 @@ release(): void;
## Caller.off
off(type: "release", callback: OnReleaseCallback): void;
off(type: 'release', callback: OnReleaseCallback): void;
取消注册通用组件服务端Stub(桩)断开监听通知。预留能力,当前暂未支持。
......@@ -635,17 +635,17 @@ off(type: "release", callback: OnReleaseCallback): void;
export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "MainUIAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'MainUIAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
try {
let onReleaseCallBack = (str) => {
console.log(' Caller OnRelease CallBack is called ' + str);
};
caller.on("release", onReleaseCallBack);
caller.off("release", onReleaseCallBack);
caller.on('release', onReleaseCallBack);
caller.off('release', onReleaseCallBack);
} catch (error) {
console.log('Caller.on or Caller.off catch error, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
......@@ -660,7 +660,7 @@ off(type: "release", callback: OnReleaseCallback): void;
## Caller.off
off(type: "release"): void;
off(type: 'release'): void;
取消注册通用组件服务端Stub(桩)断开监听通知。预留能力,当前暂未支持。
......@@ -686,17 +686,17 @@ off(type: "release"): void;
export default class MainUIAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "MainUIAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'MainUIAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
try {
let onReleaseCallBack = (str) => {
console.log(' Caller OnRelease CallBack is called ' + str);
};
caller.on("release", onReleaseCallBack);
caller.off("release");
caller.on('release', onReleaseCallBack);
caller.off('release');
} catch (error) {
console.error('Caller.on or Caller.off catch error, error.code: ' + JSON.stringify(error.code) +
' error.message: ' + JSON.stringify(error.message));
......@@ -740,8 +740,8 @@ on(method: string, callback: CalleeCallback): void;
```ts
class MyMessageAble{
name:""
str:""
name:''
str:''
num: 1
constructor(name, str) {
this.name = name;
......@@ -763,9 +763,9 @@ on(method: string, callback: CalleeCallback): void;
let method = 'call_Function';
function funcCallBack(pdata) {
console.log('Callee funcCallBack is called ' + pdata);
let msg = new MyMessageAble("test", "");
let msg = new MyMessageAble('test', '');
pdata.readSequenceable(msg);
return new MyMessageAble("test1", "Callee test");
return new MyMessageAble('test1', 'Callee test');
}
export default class MainUIAbility extends UIAbility {
onCreate(want, launchParam) {
......
......@@ -25,7 +25,7 @@ import Want from '@ohos.app.ability.Want';
| [action](js-apis-app-ability-wantConstant.md#wantConstant.Action) | string | 否 | 表示要执行的通用操作(如:查看、分享、应用详情)。在隐式Want中,您可以定义该字段,配合uri或parameters来表示对数据要执行的操作。隐式Want定义及匹配规则请参见[显式Want与隐式Want匹配规则](application-models/explicit-implicit-want-mappings.md)。 |
| [entities](js-apis-app-ability-wantConstant.md#wantConstant.Entity) | Array\<string> | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器)。在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。 |
| uri | string | 否 | 表示携带的数据,一般配合type使用,指明待处理的数据类型。如果在Want中指定了uri,则Want将匹配指定的Uri信息,包括`scheme``schemeSpecificPart``authority``path`信息。 |
| type | string | 否 | 表示MIME type类型描述,打开文件的类型,主要用于文管打开文件。比如:"text/xml" 、 "image/*"等,MIME定义请参见https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com。 |
| type | string | 否 | 表示MIME type类型描述,打开文件的类型,主要用于文管打开文件。比如:'text/xml' 、 'image/*'等,MIME定义请参见https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com。 |
| parameters | {[key: string]: any} | 否 | 表示WantParams描述,由开发者自行决定传入的键值对。默认会携带以下key值:<br />- ohos.aafwk.callerPid:表示拉起方的pid。<br />- ohos.aafwk.param.callerToken:表示拉起方的token。<br />- ohos.aafwk.param.callerUid:表示[BundleInfo](js-apis-bundleManager-bundleInfo.md#bundleinfo-1)中的uid,应用包里应用程序的uid。<br />- component.startup.newRules:表示是否启用新的管控规则。<br />- moduleName:表示拉起方的模块名,该字段的值即使定义成其他字符串,在传递到另一端时会被修改为正确的值。<br />- ohos.dlp.params.sandbox:表示dlp文件才会有。 |
| [flags](js-apis-ability-wantConstant.md#wantconstantflags) | number | 否 | 表示处理Want的方式。默认传数字。<br />例如通过wantConstant.Flags.FLAG_ABILITY_CONTINUATION表示是否以设备间迁移方式启动Ability。 |
......@@ -35,15 +35,15 @@ import Want from '@ohos.app.ability.Want';
```ts
let want = {
"deviceId": "", // deviceId为空表示本设备
"bundleName": "com.example.myapplication",
"abilityName": "FuncAbility",
"moduleName": "entry" // moduleName非必选
'deviceId': '', // deviceId为空表示本设备
'bundleName': 'com.example.myapplication',
'abilityName': 'FuncAbility',
'moduleName': 'entry' // moduleName非必选
};
this.context.startAbility(want, (error) => {
// 显式拉起Ability,通过bundleName、abilityName和moduleName可以唯一确定一个Ability
console.log("error.code = " + error.code)
})
console.log('error.code = ' + error.code);
});
```
- 通过自定字段传递数据, 以下为当前支持类型(在UIAbility对象中调用,其中示例中的context为UIAbility的上下文对象)。
......@@ -51,84 +51,84 @@ import Want from '@ohos.app.ability.Want';
* 字符串(String)
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
parameters: {
keyForString: "str",
keyForString: 'str',
},
}
};
```
* 数字(Number)
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
parameters: {
keyForInt: 100,
keyForDouble: 99.99,
},
}
};
```
* 布尔(Boolean)
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
parameters: {
keyForBool: true,
},
}
};
```
* 对象(Object)
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
parameters: {
keyForObject: {
keyForObjectString: "str",
keyForObjectString: 'str',
keyForObjectInt: -200,
keyForObjectDouble: 35.5,
keyForObjectBool: false,
},
},
}
};
```
* 数组(Array)
```ts
let want = {
bundleName: "com.example.myapplication",
abilityName: "FuncAbility",
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
parameters: {
keyForArrayString: ["str1", "str2", "str3"],
keyForArrayString: ['str1', 'str2', 'str3'],
keyForArrayInt: [100, 200, 300, 400],
keyForArrayDouble: [0.1, 0.2],
keyForArrayObject: [{obj1: "aaa"}, {obj2: 100}],
keyForArrayObject: [{obj1: 'aaa'}, {obj2: 100}],
},
}
};
```
* 文件描述符(FD)
```ts
import fileio from '@ohos.fileio';
let fd;
try {
fd = fileio.openSync("/data/storage/el2/base/haps/pic.png");
fd = fileio.openSync('/data/storage/el2/base/haps/pic.png');
} catch(e) {
console.log("openSync fail:" + JSON.stringify(e));
console.log('openSync fail:' + JSON.stringify(e));
}
let want = {
"deviceId": "", // deviceId为空表示本设备
"bundleName": "com.example.myapplication",
"abilityName": "FuncAbility",
"moduleName": "entry", // moduleName非必选
"parameters": {
"keyFd":{"type":"FD", "value":fd} // {"type":"FD", "value":fd}是固定用法,用于表示该数据是FD
'deviceId': '', // deviceId为空表示本设备
'bundleName': 'com.example.myapplication',
'abilityName': 'FuncAbility',
'moduleName': 'entry', // moduleName非必选
'parameters': {
'keyFd':{'type':'FD', 'value':fd} // {'type':'FD', 'value':fd}是固定用法,用于表示该数据是FD
}
};
this.context.startAbility(want, (error) => {
// 显式拉起Ability,通过bundleName、abilityName和moduleName可以唯一确定一个Ability
console.log("error.code = " + error.code)
})
console.log('error.code = ' + error.code)
});
```
- 更多详细说明和示例请参见: [应用模型](../../application-models/Readme-CN.md)的信息传递载体Want
......
......@@ -85,7 +85,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -180,7 +180,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
try {
WantAgent.getWantAgent(wantAgentInfo).then((data) => {
......@@ -268,7 +268,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -378,7 +378,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -480,7 +480,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -590,7 +590,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -692,7 +692,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -804,7 +804,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -905,7 +905,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -1015,7 +1015,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -1091,8 +1091,8 @@ trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: AsyncCallback\<Co
let wantAgent;
// triggerInfo
let triggerInfo = {
code: 0 //自定义义结果码
}
code: 0 //自定义义结果码
};
//WantAgentInfo对象
let wantAgentInfo = {
wants: [
......@@ -1119,7 +1119,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -1226,7 +1226,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -1339,7 +1339,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -1439,7 +1439,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......@@ -1547,7 +1547,7 @@ let wantAgentInfo = {
operationType: WantAgent.OperationType.START_ABILITIES,
requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}
};
//getWantAgent回调
function getWantAgentCallback(err, data) {
......
......@@ -8,7 +8,7 @@ wantConstant模块提供want中操作want常数和解释Flags说明的能力。
## 导入模块
```js
```ts
import wantConstant from '@ohos.app.ability.wantConstant';
```
......
......@@ -35,7 +35,7 @@ createFormBindingData(obj?: Object | string): FormBindingData
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| obj | Object\|string | 否 | js卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。其中图片数据以"formImages"作为标识,内容为图片标识与图片文件描述符的键值对{"formImages": {"key1": fd1, "key2": fd2}} |
| obj | Object\|string | 否 | js卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。其中图片数据以'formImages'作为标识,内容为图片标识与图片文件描述符的键值对{'formImages': {'key1': fd1, 'key2': fd2}} |
**返回值:**
......@@ -52,10 +52,10 @@ import formBindingData from '@ohos.app.form.formBindingData';
import fs from '@ohos.file.fs';
try {
let fd = fs.openSync('/path/to/form.png')
let fd = fs.openSync('/path/to/form.png');
let obj = {
"temperature": "21°",
"formImages": { "image": fd }
'temperature': '21°',
'formImages': { 'image': fd }
};
formBindingData.createFormBindingData(obj);
} catch (error) {
......
......@@ -51,8 +51,8 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) {
console.log('FormExtensionAbility onAddForm, want:' + want.abilityName);
let dataObj1 = {
temperature: "11c",
"time": "11:00"
temperature: '11c',
'time': '11:00'
};
let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1;
......@@ -111,8 +111,8 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
onUpdateForm(formId) {
console.log('FormExtensionAbility onUpdateForm, formId:' + formId);
let obj2 = formBindingData.createFormBindingData({
temperature: "22c",
time: "22:00"
temperature: '22c',
time: '22:00'
});
formProvider.updateForm(formId, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data:' + data);
......@@ -141,19 +141,19 @@ onChangeFormVisibility(newStatus: { [key: string]: number }): void
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData'
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onChangeFormVisibility(newStatus) {
console.log('FormExtensionAbility onChangeFormVisibility, newStatus:' + newStatus);
let obj2 = formBindingData.createFormBindingData({
temperature: "22c",
time: "22:00"
temperature: '22c',
time: '22:00'
});
for (let key in newStatus) {
console.log('FormExtensionAbility onChangeFormVisibility, key:' + key + ", value=" + newStatus[key]);
console.log('FormExtensionAbility onChangeFormVisibility, key:' + key + ', value=' + newStatus[key]);
formProvider.updateForm(key, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data:' + data);
}).catch((error) => {
......@@ -186,7 +186,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
console.log('FormExtensionAbility onFormEvent, formId:' + formId + ", message:" + message);
console.log('FormExtensionAbility onFormEvent, formId:' + formId + ', message:' + message);
}
};
```
......@@ -302,8 +302,8 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
onShareForm(formId) {
console.log('FormExtensionAbility onShareForm, formId:' + formId);
let wantParams = {
"temperature": "20",
"time": "2022-8-8 09:59",
'temperature': '20',
'time': '2022-8-8 09:59',
};
return wantParams;
}
......
......@@ -43,7 +43,7 @@ deleteForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.app.form.formHost';
try {
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.deleteForm(formId, (error) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -92,7 +92,7 @@ deleteForm(formId: string): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.deleteForm(formId).then(() => {
console.log('formHost deleteForm success');
}).catch((error) => {
......@@ -133,7 +133,7 @@ releaseForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.app.form.formHost';
try {
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.releaseForm(formId, (error) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -175,7 +175,7 @@ releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback&lt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.releaseForm(formId, true, (error) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -222,7 +222,7 @@ releaseForm(formId: string, isReleaseCache?: boolean): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.releaseForm(formId, true).then(() => {
console.log('formHost releaseForm success');
}).catch((error) => {
......@@ -263,7 +263,7 @@ requestForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.app.form.formHost';
try {
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.requestForm(formId, (error) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -309,7 +309,7 @@ requestForm(formId: string): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.requestForm(formId).then(() => {
console.log('formHost requestForm success');
}).catch((error) => {
......@@ -351,7 +351,7 @@ castToNormalForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
import formHost from '@ohos.app.form.formHost';
try {
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.castToNormalForm(formId, (error) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -397,7 +397,7 @@ castToNormalForm(formId: string): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.castToNormalForm(formId).then(() => {
console.log('formHost castTempForm success');
}).catch((error) => {
......@@ -438,7 +438,7 @@ notifyVisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
import formHost from '@ohos.app.form.formHost';
try {
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.notifyVisibleForms(formId, (error) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -484,7 +484,7 @@ notifyVisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.notifyVisibleForms(formId).then(() => {
console.log('formHost notifyVisibleForms success');
}).catch((error) => {
......@@ -525,7 +525,7 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;vo
import formHost from '@ohos.app.form.formHost';
try {
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.notifyInvisibleForms(formId, (error) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -571,7 +571,7 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.notifyInvisibleForms(formId).then(() => {
console.log('formHost notifyInvisibleForms success');
}).catch((error) => {
......@@ -612,7 +612,7 @@ enableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&
import formHost from '@ohos.app.form.formHost';
try {
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.enableFormsUpdate(formId, (error) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -658,7 +658,7 @@ enableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.enableFormsUpdate(formId).then(() => {
console.log('formHost enableFormsUpdate success');
}).catch((error) => {
......@@ -699,7 +699,7 @@ disableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
import formHost from '@ohos.app.form.formHost';
try {
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.disableFormsUpdate(formId, (error) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -745,7 +745,7 @@ disableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.disableFormsUpdate(formId).then(() => {
console.log('formHost disableFormsUpdate success');
}).catch((error) => {
......@@ -912,7 +912,7 @@ getFormsInfo(bundleName: string, callback: AsyncCallback&lt;Array&lt;formInfo.Fo
import formHost from '@ohos.app.form.formHost';
try {
formHost.getFormsInfo("com.example.ohos.formjsdemo", (error, data) => {
formHost.getFormsInfo('com.example.ohos.formjsdemo', (error, data) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
} else {
......@@ -955,7 +955,7 @@ getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback&lt;
import formHost from '@ohos.app.form.formHost';
try {
formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry", (error, data) => {
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error, data) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
} else {
......@@ -1003,7 +1003,7 @@ getFormsInfo(bundleName: string, moduleName?: string): Promise&lt;Array&lt;formI
import formHost from '@ohos.app.form.formHost';
try {
formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry").then((data) => {
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data) => {
console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
}).catch((error) => {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -1036,7 +1036,7 @@ deleteInvalidForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;numb
import formHost from '@ohos.app.form.formHost';
try {
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds, (error, data) => {
if (error) {
console.log(`error, code: ${error.code}, message: ${error.message}`);
......@@ -1077,7 +1077,7 @@ deleteInvalidForms(formIds: Array&lt;string&gt;): Promise&lt;number&gt;
import formHost from '@ohos.app.form.formHost';
try {
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds).then((data) => {
console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
}).catch((error) => {
......@@ -1118,13 +1118,13 @@ acquireFormState(want: Want, callback: AsyncCallback&lt;formInfo.FormStateInfo&g
import formHost from '@ohos.app.form.formHost';
let want = {
"deviceId": "",
"bundleName": "ohos.samples.FormApplication",
"abilityName": "FormAbility",
"parameters": {
"ohos.extra.param.key.module_name": "entry",
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.form_dimension": 2
'deviceId': '',
'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility',
'parameters': {
'ohos.extra.param.key.module_name': 'entry',
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.form_dimension': 2
}
};
try {
......@@ -1175,13 +1175,13 @@ acquireFormState(want: Want): Promise&lt;formInfo.FormStateInfo&gt;
import formHost from '@ohos.app.form.formHost';
let want = {
"deviceId": "",
"bundleName": "ohos.samples.FormApplication",
"abilityName": "FormAbility",
"parameters": {
"ohos.extra.param.key.module_name": "entry",
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.form_dimension": 2
'deviceId': '',
'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility',
'parameters': {
'ohos.extra.param.key.module_name': 'entry',
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.form_dimension': 2
}
};
try {
......@@ -1195,9 +1195,9 @@ try {
}
```
## on("formUninstall")
## on('formUninstall')
on(type: "formUninstall", callback: Callback&lt;string&gt;): void
on(type: 'formUninstall', callback: Callback&lt;string&gt;): void
订阅卡片卸载事件。使用callback异步回调。
......@@ -1207,7 +1207,7 @@ on(type: "formUninstall", callback: Callback&lt;string&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| type | string | 是 | 填写"formUninstall",表示卡片卸载事件。 |
| type | string | 是 | 填写'formUninstall',表示卡片卸载事件。 |
| callback | Callback&lt;string&gt; | 是 | 回调函数。返回卡片标识。 |
**示例:**
......@@ -1218,12 +1218,12 @@ import formHost from '@ohos.app.form.formHost';
let callback = function(formId) {
console.log('formHost on formUninstall, formId:' + formId);
}
formHost.on("formUninstall", callback);
formHost.on('formUninstall', callback);
```
## off("formUninstall")
## off('formUninstall')
off(type: "formUninstall", callback?: Callback&lt;string&gt;): void
off(type: 'formUninstall', callback?: Callback&lt;string&gt;): void
取消订阅卡片卸载事件。使用callback异步回调。
......@@ -1233,8 +1233,8 @@ off(type: "formUninstall", callback?: Callback&lt;string&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| type | string | 是 | 填写"formUninstall",表示卡片卸载事件。 |
| callback | Callback&lt;string&gt; | 否 | 回调函数。返回卡片标识。缺省时,表示注销所有已注册事件回调。<br> 需与对应on("formUninstall")的callback一致。|
| type | string | 是 | 填写'formUninstall',表示卡片卸载事件。 |
| callback | Callback&lt;string&gt; | 否 | 回调函数。返回卡片标识。缺省时,表示注销所有已注册事件回调。<br> 需与对应on('formUninstall')的callback一致。|
**示例:**
......@@ -1244,7 +1244,7 @@ import formHost from '@ohos.app.form.formHost';
let callback = function(formId) {
console.log('formHost on formUninstall, formId:' + formId);
}
formHost.off("formUninstall", callback);
formHost.off('formUninstall', callback);
```
## notifyFormsVisible
......@@ -1277,7 +1277,7 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean, callback: A
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsVisible(formIds, true, (error) => {
if (error) {
......@@ -1324,7 +1324,7 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean): Promise&lt
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsVisible(formIds, true).then(() => {
console.log('formHost notifyFormsVisible success');
......@@ -1366,7 +1366,7 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean, c
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsEnableUpdate(formIds, true, (error) => {
if (error) {
......@@ -1413,7 +1413,7 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean):
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
console.log('formHost notifyFormsEnableUpdate success');
......@@ -1454,8 +1454,8 @@ shareForm(formId: string, deviceId: string, callback: AsyncCallback&lt;void&gt;)
```ts
import formHost from '@ohos.app.form.formHost';
let formId = "12400633174999288";
let deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
let formId = '12400633174999288';
let deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
try {
formHost.shareForm(formId, deviceId, (error) => {
if (error) {
......@@ -1502,8 +1502,8 @@ shareForm(formId: string, deviceId: string): Promise&lt;void&gt;
```ts
import formHost from '@ohos.app.form.formHost';
let formId = "12400633174999288";
let deviceId = "EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2";
let formId = '12400633174999288';
let deviceId = 'EFC11C0C53628D8CC2F8CB5052477E130D075917034613B9884C55CD22B3DEF2';
try {
formHost.shareForm(formId, deviceId).then(() => {
console.log('formHost shareForm success');
......@@ -1545,7 +1545,7 @@ notifyFormsPrivacyProtected(formIds: Array\<string>, isProtected: boolean, callb
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsPrivacyProtected(formIds, true, (error) => {
if (error) {
......@@ -1590,7 +1590,7 @@ function notifyFormsPrivacyProtected(formIds: Array\<string\>, isProtected: bool
```ts
import formHost from '@ohos.app.form.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
try {
formHost.notifyFormsPrivacyProtected(formIds, true).then(() => {
console.log('formHost notifyFormsPrivacyProtected success');
......
......@@ -92,16 +92,16 @@ import formInfo from '@ohos.app.form.formInfo';
| 名称 | 值 | 说明 |
| ----------- | ---- | ------------ |
| IDENTITY_KEY | "ohos.extra.param.key.form_identity" | 卡片标识。 |
| DIMENSION_KEY | "ohos.extra.param.key.form_dimension" | 卡片规格样式。 |
| NAME_KEY | "ohos.extra.param.key.form_name" | 卡片名称。 |
| MODULE_NAME_KEY | "ohos.extra.param.key.module_name" | 卡片所属模块名称。 |
| WIDTH_KEY | "ohos.extra.param.key.form_width" | 卡片宽度。 |
| HEIGHT_KEY | "ohos.extra.param.key.form_height" | 卡片高度。 |
| TEMPORARY_KEY | "ohos.extra.param.key.form_temporary" | 临时卡片。 |
| ABILITY_NAME_KEY | "ohos.extra.param.key.ability_name" | ability名称。 |
| DEVICE_ID_KEY | "ohos.extra.param.key.device_id" | 设备标识。 |
| BUNDLE_NAME_KEY | "ohos.extra.param.key.bundle_name" | 指示指定要获取的捆绑Bundle名称的键。 |
| IDENTITY_KEY | 'ohos.extra.param.key.form_identity' | 卡片标识。 |
| DIMENSION_KEY | 'ohos.extra.param.key.form_dimension' | 卡片规格样式。 |
| NAME_KEY | 'ohos.extra.param.key.form_name' | 卡片名称。 |
| MODULE_NAME_KEY | 'ohos.extra.param.key.module_name' | 卡片所属模块名称。 |
| WIDTH_KEY | 'ohos.extra.param.key.form_width' | 卡片宽度。 |
| HEIGHT_KEY | 'ohos.extra.param.key.form_height' | 卡片高度。 |
| TEMPORARY_KEY | 'ohos.extra.param.key.form_temporary' | 临时卡片。 |
| ABILITY_NAME_KEY | 'ohos.extra.param.key.ability_name' | ability名称。 |
| DEVICE_ID_KEY | 'ohos.extra.param.key.device_id' | 设备标识。 |
| BUNDLE_NAME_KEY | 'ohos.extra.param.key.bundle_name' | 指示指定要获取的捆绑Bundle名称的键。 |
## FormDimension
......
......@@ -39,7 +39,7 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l
```ts
import formProvider from '@ohos.app.form.formProvider';
let formId = "12400633174999288";
let formId = '12400633174999288';
try {
formProvider.setFormNextRefreshTime(formId, 5, (error, data) => {
if (error) {
......@@ -86,7 +86,7 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt;
```ts
import formProvider from '@ohos.app.form.formProvider';
let formId = "12400633174999288";
let formId = '12400633174999288';
try {
formProvider.setFormNextRefreshTime(formId, 5).then(() => {
console.log(`formProvider setFormNextRefreshTime success`);
......@@ -127,9 +127,9 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let formId = "12400633174999288";
let formId = '12400633174999288';
try {
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
formProvider.updateForm(formId, obj, (error, data) => {
if (error) {
console.log(`callback error, code: ${error.code}, message: ${error.message})`);
......@@ -176,8 +176,8 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let formId = "12400633174999288";
let obj = formBindingData.createFormBindingData({ temperature: "22c", time: "22:00" });
let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({ temperature: '22c', time: '22:00' });
try {
formProvider.updateForm(formId, obj).then(() => {
console.log(`formProvider updateForm success`);
......@@ -258,7 +258,7 @@ import formProvider from '@ohos.app.form.formProvider';
const filter: formInfo.FormInfoFilter = {
// get info of forms belong to module entry.
moduleName: "entry"
moduleName: 'entry'
};
try {
formProvider.getFormsInfo(filter, (error, data) => {
......@@ -308,7 +308,7 @@ import formProvider from '@ohos.app.form.formProvider';
const filter: formInfo.FormInfoFilter = {
// get info of forms belong to module entry.
moduleName: "entry"
moduleName: 'entry'
};
try {
formProvider.getFormsInfo(filter).then((data) => {
......@@ -335,7 +335,7 @@ requestPublishForm(want: Want, formBindingData: formBindingData.FormBindingData,
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ---------------------------------------------------------------------- | ---- | ---------------- |
| want | [Want](js-apis-application-want.md) | 是 | 发布请求。需包含以下字段。<br>abilityName: 目标卡片ability<br>parameters:<br>"ohos.extra.param.key.form_dimension"<br>"ohos.extra.param.key.form_name"<br>"ohos.extra.param.key.module_name" |
| want | [Want](js-apis-application-want.md) | 是 | 发布请求。需包含以下字段。<br>abilityName: 目标卡片ability<br>parameters:<br>'ohos.extra.param.key.form_dimension'<br>'ohos.extra.param.key.form_name'<br>'ohos.extra.param.key.module_name' |
| formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | 是 | 创建卡片的数据。 |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。返回卡片标识。 |
......@@ -353,15 +353,15 @@ import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let want = {
abilityName: "FormAbility",
abilityName: 'FormAbility',
parameters: {
"ohos.extra.param.key.form_dimension": 2,
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.module_name": "entry"
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
try {
let obj = formBindingData.createFormBindingData({ temperature: "22c", time: "22:00" });
let obj = formBindingData.createFormBindingData({ temperature: '22c', time: '22:00' });
formProvider.requestPublishForm(want, obj, (error, data) => {
if (error) {
console.log(`callback error, code: ${error.code}, message: ${error.message})`);
......@@ -388,7 +388,7 @@ requestPublishForm(want: Want, callback: AsyncCallback&lt;string&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-want.md) | 是 | 发布请求。需包含以下字段。<br>abilityName: 目标卡片ability<br>parameters:<br>"ohos.extra.param.key.form_dimension"<br>"ohos.extra.param.key.form_name"<br>"ohos.extra.param.key.module_name" |
| want | [Want](js-apis-application-want.md) | 是 | 发布请求。需包含以下字段。<br>abilityName: 目标卡片ability<br>parameters:<br>'ohos.extra.param.key.form_dimension'<br>'ohos.extra.param.key.form_name'<br>'ohos.extra.param.key.module_name' |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。返回卡片标识。 |
**错误码:**
......@@ -404,11 +404,11 @@ requestPublishForm(want: Want, callback: AsyncCallback&lt;string&gt;): void
import formProvider from '@ohos.app.form.formProvider';
let want = {
abilityName: "FormAbility",
abilityName: 'FormAbility',
parameters: {
"ohos.extra.param.key.form_dimension": 2,
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.module_name": "entry"
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
try {
......@@ -438,7 +438,7 @@ requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData
| 参数名 | 类型 | 必填 | 说明 |
| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-want.md) | 是 | 发布请求。需包含以下字段。<br>abilityName: 目标卡片ability<br>parameters:<br>"ohos.extra.param.key.form_dimension"<br>"ohos.extra.param.key.form_name"<br>"ohos.extra.param.key.module_name" |
| want | [Want](js-apis-application-want.md) | 是 | 发布请求。需包含以下字段。<br>abilityName: 目标卡片ability<br>parameters:<br>'ohos.extra.param.key.form_dimension'<br>'ohos.extra.param.key.form_name'<br>'ohos.extra.param.key.module_name' |
| formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | 否 | 创建卡片的数据。 |
**返回值:**
......@@ -460,11 +460,11 @@ requestPublishForm(want: Want, formBindingData?: formBindingData.FormBindingData
import formProvider from '@ohos.app.form.formProvider';
let want = {
abilityName: "FormAbility",
abilityName: 'FormAbility',
parameters: {
"ohos.extra.param.key.form_dimension": 2,
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.module_name": "entry"
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
try {
......@@ -506,11 +506,11 @@ try {
} else {
if (isSupported) {
var want = {
abilityName: "FormAbility",
abilityName: 'FormAbility',
parameters: {
"ohos.extra.param.key.form_dimension": 2,
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.module_name": "entry"
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
try {
......@@ -557,11 +557,11 @@ try {
formProvider.isRequestPublishFormSupported().then((isSupported) => {
if (isSupported) {
var want = {
abilityName: "FormAbility",
abilityName: 'FormAbility',
parameters: {
"ohos.extra.param.key.form_dimension": 2,
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.module_name": "entry"
'ohos.extra.param.key.form_dimension': 2,
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.module_name': 'entry'
}
};
try {
......
......@@ -207,12 +207,12 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
**示例:**
```ts
import AbilityConstant from "@ohos.app.ability.AbilityConstant";
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
export default class EntryAbility extends UIAbility {
onContinue(wantParams) {
console.log('onContinue');
wantParams["myData"] = "my1234567";
wantParams['myData'] = 'my1234567';
return AbilityConstant.OnContinueResult.AGREE;
}
}
......@@ -289,7 +289,7 @@ dump(params: Array\<string>): Array\<string>;
export default class EntryAbility extends UIAbility {
dump(params) {
console.log('dump, params:' + JSON.stringify(params));
return ["params"]
return ['params'];
}
}
```
......@@ -347,7 +347,7 @@ import AbilityConstant from '@ohos.app.ability.AbilityConstant';
export default class EntryAbility extends UIAbility {
onSaveState(reason, wantParam) {
console.log('onSaveState');
wantParam["myData"] = "my1234567";
wantParam['myData'] = 'my1234567';
return AbilityConstant.OnSaveResult.RECOVERY_AGREE;
}
}
......@@ -394,8 +394,8 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
import UIAbility from '@ohos.app.ability.UIAbility';
class MyMessageAble { // 自定义的Sequenceable数据结构
name:""
str:""
name:''
str:''
num: 1
constructor(name, str) {
this.name = name;
......@@ -419,12 +419,12 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "EntryAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'EntryAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
let msg = new MyMessageAble("msg", "world"); // 参考Sequenceable数据定义
let msg = new MyMessageAble('msg', 'world'); // 参考Sequenceable数据定义
caller.call(method, msg)
.then(() => {
console.log('Caller call() called');
......@@ -479,8 +479,8 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa
import UIAbility from '@ohos.app.ability.UIAbility';
class MyMessageAble{
name:""
str:""
name:''
str:''
num: 1
constructor(name, str) {
this.name = name;
......@@ -504,16 +504,16 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "EntryAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'EntryAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
let msg = new MyMessageAble(1, "world");
let msg = new MyMessageAble(1, 'world');
caller.callWithResult(method, msg)
.then((data) => {
console.log('Caller callWithResult() called');
let retmsg = new MyMessageAble(0, "");
let retmsg = new MyMessageAble(0, '');
data.readSequenceable(retmsg);
})
.catch((callErr) => {
......@@ -556,9 +556,9 @@ release(): void;
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "EntryAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'EntryAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
try {
......@@ -599,9 +599,9 @@ release(): void;
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
this.context.startAbilityByCall({
bundleName: "com.example.myservice",
abilityName: "EntryAbility",
deviceId: ""
bundleName: 'com.example.myservice',
abilityName: 'EntryAbility',
deviceId: ''
}).then((obj) => {
caller = obj;
try {
......@@ -653,8 +653,8 @@ on(method: string, callback: CalleeCallBack): void;
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
class MyMessageAble{
name:""
str:""
name:''
str:''
num: 1
constructor(name, str) {
this.name = name;
......@@ -676,9 +676,9 @@ on(method: string, callback: CalleeCallBack): void;
let method = 'call_Function';
function funcCallBack(pdata) {
console.log('Callee funcCallBack is called ' + pdata);
let msg = new MyMessageAble("test", "");
let msg = new MyMessageAble('test', '');
pdata.readSequenceable(msg);
return new MyMessageAble("test1", "Callee test");
return new MyMessageAble('test1', 'Callee test');
}
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
......
......@@ -66,7 +66,7 @@ getArguments(): AbilityDelegatorArgs
```ts
let args = AbilityDelegatorRegistry.getArguments();
console.info("getArguments bundleName:" + args.bundleName);
console.info("getArguments testCaseNames:" + args.testCaseNames);
console.info("getArguments testRunnerClassName:" + args.testRunnerClassName);
console.info('getArguments bundleName:' + args.bundleName);
console.info('getArguments testCaseNames:' + args.testCaseNames);
console.info('getArguments testRunnerClassName:' + args.testRunnerClassName);
```
# @ohos.application.AbilityLifecycleCallback (AbilityLifecycleCallback)
AbilityLifecycleCallback模块提供应用上下文ApplicationContext的生命周期监听方法的回调类的能力,包括onAbilityCreate、onWindowStageCreate、onWindowStageDestroy等方法,可以作为[on(type: "abilityLifecycle", callback: AbilityLifecycleCallback)](js-apis-inner-application-applicationContext.md#applicationcontextontype-abilitylifecycle-callback-abilitylifecyclecallback)的入参。
AbilityLifecycleCallback模块提供应用上下文ApplicationContext的生命周期监听方法的回调类的能力,包括onAbilityCreate、onWindowStageCreate、onWindowStageDestroy等方法,可以作为[on(type: 'abilityLifecycle', callback: AbilityLifecycleCallback)](js-apis-inner-application-applicationContext.md#applicationcontextontype-abilitylifecycle-callback-abilitylifecyclecallback)的入参。
> **说明:**
>
......@@ -11,7 +11,7 @@ AbilityLifecycleCallback模块提供应用上下文ApplicationContext的生命
## 导入模块
```ts
import AbilityLifecycleCallback from "@ohos.application.AbilityLifecycleCallback";
import AbilityLifecycleCallback from '@ohos.application.AbilityLifecycleCallback';
```
......@@ -156,57 +156,57 @@ onAbilityContinue(ability: Ability): void;
**示例:**
```ts
import AbilityStage from "@ohos.app.ability.AbilityStage";
import AbilityStage from '@ohos.app.ability.AbilityStage';
let lifecycleId;
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log('MyAbilityStage onCreate')
let AbilityLifecycleCallback = {
onAbilityCreate(ability) {
console.log("onAbilityCreate ability:" + JSON.stringify(ability));
console.log('onAbilityCreate ability:' + JSON.stringify(ability));
},
onWindowStageCreate(ability, windowStage) {
console.log("onWindowStageCreate ability:" + JSON.stringify(ability));
console.log("onWindowStageCreate windowStage:" + JSON.stringify(windowStage));
console.log('onWindowStageCreate ability:' + JSON.stringify(ability));
console.log('onWindowStageCreate windowStage:' + JSON.stringify(windowStage));
},
onWindowStageActive(ability, windowStage) {
console.log("onWindowStageActive ability:" + JSON.stringify(ability));
console.log("onWindowStageActive windowStage:" + JSON.stringify(windowStage));
console.log('onWindowStageActive ability:' + JSON.stringify(ability));
console.log('onWindowStageActive windowStage:' + JSON.stringify(windowStage));
},
onWindowStageInactive(ability, windowStage) {
console.log("onWindowStageInactive ability:" + JSON.stringify(ability));
console.log("onWindowStageInactive windowStage:" + JSON.stringify(windowStage));
console.log('onWindowStageInactive ability:' + JSON.stringify(ability));
console.log('onWindowStageInactive windowStage:' + JSON.stringify(windowStage));
},
onWindowStageDestroy(ability, windowStage) {
console.log("onWindowStageDestroy ability:" + JSON.stringify(ability));
console.log("onWindowStageDestroy windowStage:" + JSON.stringify(windowStage));
console.log('onWindowStageDestroy ability:' + JSON.stringify(ability));
console.log('onWindowStageDestroy windowStage:' + JSON.stringify(windowStage));
},
onAbilityDestroy(ability) {
console.log("onAbilityDestroy ability:" + JSON.stringify(ability));
console.log('onAbilityDestroy ability:' + JSON.stringify(ability));
},
onAbilityForeground(ability) {
console.log("onAbilityForeground ability:" + JSON.stringify(ability));
console.log('onAbilityForeground ability:' + JSON.stringify(ability));
},
onAbilityBackground(ability) {
console.log("onAbilityBackground ability:" + JSON.stringify(ability));
console.log('onAbilityBackground ability:' + JSON.stringify(ability));
},
onAbilityContinue(ability) {
console.log("onAbilityContinue ability:" + JSON.stringify(ability));
console.log('onAbilityContinue ability:' + JSON.stringify(ability));
}
}
// 1.通过context属性获取applicationContext
let applicationContext = this.context.getApplicationContext();
// 2.通过applicationContext注册监听应用内生命周期
lifecycleId = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleId));
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));
});
}
}
......
......@@ -51,11 +51,11 @@ updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
```ts
let config = {
language: 'chinese'
}
};
abilityManager.updateConfiguration(config, () => {
console.log('------------ updateConfiguration -----------');
})
});
```
## updateConfiguration
......@@ -85,13 +85,13 @@ updateConfiguration(config: Configuration): Promise\<void>
```ts
let config = {
language: 'chinese'
}
};
abilityManager.updateConfiguration(config).then(() => {
console.log('updateConfiguration success');
}).catch((err) => {
console.log('updateConfiguration fail');
})
});
```
## getAbilityRunningInfos
......@@ -114,7 +114,7 @@ getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): vo
```ts
abilityManager.getAbilityRunningInfos((err,data) => {
console.log("getAbilityRunningInfos err: " + err + " data: " + JSON.stringify(data));
console.log('getAbilityRunningInfos err: ' + err + ' data: ' + JSON.stringify(data));
});
```
......@@ -138,8 +138,8 @@ getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
```ts
abilityManager.getAbilityRunningInfos().then((data) => {
console.log("getAbilityRunningInfos data: " + JSON.stringify(data))
console.log('getAbilityRunningInfos data: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getAbilityRunningInfos err: " + err)
console.log('getAbilityRunningInfos err: ' + err);
});
```
\ No newline at end of file
......@@ -9,7 +9,7 @@
## 导入模块
```ts
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility'
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility';
```
## 属性
......@@ -137,7 +137,7 @@ onAccessibilityEvent(event: AccessibilityEvent): void;
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
onAccessibilityEvent(event) {
console.log('AxExtensionAbility onAccessibilityEvent');
if (event.eventType == 'click') {
if (event.eventType === 'click') {
console.log('AxExtensionAbility onAccessibilityEvent: click');
}
}
......@@ -164,7 +164,7 @@ onKeyEvent(keyEvent: KeyEvent): boolean;
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
onKeyEvent(keyEvent) {
console.log('AxExtensionAbility onKeyEvent');
if (keyEvent.keyCode == 22) {
if (keyEvent.keyCode === 22) {
console.log('AxExtensionAbility onKeyEvent: intercept 22');
return true;
}
......
......@@ -152,7 +152,7 @@ getAppMemorySize(callback: AsyncCallback\<number>): void;
appManager.getAppMemorySize((err, data) => {
console.log('error:' + JSON.stringify(err));
console.log('The size of app memory is:' + JSON.stringify(data));
})
});
```
## appManager.getProcessRunningInfos<sup>(deprecated)</sup>
......@@ -206,7 +206,7 @@ getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): vo
appManager.getProcessRunningInfos((err, data) => {
console.log('error:' + JSON.stringify(err));
console.log('The process running infos is:' + JSON.stringify(data));
})
});
```
## appManager.registerApplicationStateObserver<sup>8+</sup>
......@@ -230,7 +230,7 @@ registerApplicationStateObserver(observer: ApplicationStateObserver): number;
**示例:**
```ts
var applicationStateObserver = {
let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log('------------ onForegroundApplicationChanged -----------', appStateData);
},
......@@ -246,7 +246,7 @@ registerApplicationStateObserver(observer: ApplicationStateObserver): number;
onProcessStateChanged(processData) {
console.log('------------ onProcessStateChanged -----------', processData);
}
}
};
const observerCode = appManager.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
```
......@@ -273,7 +273,7 @@ registerApplicationStateObserver(observer: ApplicationStateObserver, bundleNameL
**示例:**
```ts
var applicationStateObserver = {
let applicationStateObserver = {
onForegroundApplicationChanged(appStateData) {
console.log('------------ onForegroundApplicationChanged -----------', appStateData);
},
......@@ -289,8 +289,8 @@ registerApplicationStateObserver(observer: ApplicationStateObserver, bundleNameL
onProcessStateChanged(processData) {
console.log('------------ onProcessStateChanged -----------', processData);
}
}
var bundleNameList = ['bundleName1', 'bundleName2'];
};
let bundleNameList = ['bundleName1', 'bundleName2'];
const observerCode = appManager.registerApplicationStateObserver(applicationStateObserver, bundleNameList);
console.log('-------- observerCode: ---------', observerCode);
```
......@@ -361,7 +361,7 @@ unregisterApplicationStateObserver(observerId: number): Promise\<void>;
})
.catch((err) => {
console.log('----------- unregisterApplicationStateObserver fail ----------', err);
})
});
```
## appManager.getForegroundApplications<sup>8+</sup>
......@@ -389,7 +389,7 @@ getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
if (err) {
console.log('--------- getForegroundApplicationsCallback fail ---------', err);
} else {
console.log('--------- getForegroundApplicationsCallback success ---------', data)
console.log('--------- getForegroundApplicationsCallback success ---------', data);
}
}
appManager.getForegroundApplications(getForegroundApplicationsCallback);
......@@ -422,7 +422,7 @@ getForegroundApplications(): Promise\<Array\<AppStateData>>;
})
.catch((err) => {
console.log('--------- getForegroundApplications fail -------', err);
})
});
```
## appManager.killProcessWithAccount<sup>8+</sup>
......@@ -455,7 +455,7 @@ appManager.killProcessWithAccount(bundleName, accountId)
})
.catch((err) => {
console.log('------------ killProcessWithAccount fail ------------', err);
})
});
```
......@@ -561,7 +561,7 @@ killProcessesByBundleName(bundleName: string): Promise\<void>;
})
.catch((err) => {
console.log('------------ killProcessesByBundleName fail ------------', err);
})
});
```
## appManager.clearUpApplicationData<sup>8+</sup>
......@@ -631,5 +631,5 @@ clearUpApplicationData(bundleName: string): Promise\<void>;
})
.catch((err) => {
console.log('------------ clearUpApplicationData fail ------------', err);
})
});
```
\ No newline at end of file
......@@ -31,7 +31,7 @@ export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: Window.WindowStage) {
let envCallback = {
onConfigurationUpdated(config) {
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`)
console.info(`envCallback onConfigurationUpdated success: ${JSON.stringify(config)}`);
let language = config.language;
let colorMode = config.colorMode;
}
......
......@@ -14,7 +14,7 @@
## 导入模块
```ts
import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility'
import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility';
```
## uri命名规则
......@@ -65,11 +65,11 @@ DataShare客户端连接DataShareExtensionAbility服务端时,服务端回调
```ts
import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
let DB_NAME = 'DB00.db';
let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
+ ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
......@@ -112,22 +112,22 @@ insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback&lt;numbe
```ts
import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
let DB_NAME = 'DB00.db';
let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
+ ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
insert(uri, valueBucket, callback) {
if (valueBucket == null) {
if (valueBucket === null) {
console.info('invalid valueBuckets');
return;
}
rdbStore.insert(TBL_NAME, valueBucket, function (err, ret) {
console.info('callback ret:' + ret);
if (callback != undefined) {
if (callback !== undefined) {
callback(err, ret);
}
});
......@@ -157,20 +157,20 @@ update?(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueB
```ts
import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
let DB_NAME = 'DB00.db';
let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
+ ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
update(uri, predicates, valueBucket, callback) {
if (predicates == null || predicates == undefined) {
if (predicates === null || predicates === undefined) {
return;
}
rdbStore.update(TBL_NAME, valueBucket, predicates, function (err, ret) {
if (callback != undefined) {
if (callback !== undefined) {
callback(err, ret);
}
});
......@@ -199,20 +199,20 @@ delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callba
```ts
import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
let DB_NAME = 'DB00.db';
let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
+ ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
delete(uri, predicates, callback) {
if (predicates == null || predicates == undefined) {
if (predicates === null || predicates === undefined) {
return;
}
rdbStore.delete(TBL_NAME, predicates, function (err, ret) {
if (callback != undefined) {
if (callback !== undefined) {
callback(err, ret);
}
});
......@@ -242,23 +242,23 @@ query?(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns
```ts
import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
let DB_NAME = 'DB00.db';
let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
+ ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
query(uri, predicates, columns, callback) {
if (predicates == null || predicates == undefined) {
if (predicates === null || predicates === undefined) {
return;
}
rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) {
if (resultSet != undefined) {
if (resultSet !== undefined) {
console.info('resultSet.rowCount: ' + resultSet.rowCount);
}
if (callback != undefined) {
if (callback !== undefined) {
callback(err, resultSet);
}
});
......@@ -287,23 +287,23 @@ batchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: Asy
```ts
import rdb from '@ohos.data.relationalStore';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
let DB_NAME = 'DB00.db';
let TBL_NAME = 'TBL00';
let DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS '
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
+ ' (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)';
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
batchInsert(uri, valueBuckets, callback) {
if (valueBuckets == null || valueBuckets.length == undefined) {
if (valueBuckets === null || valueBuckets.length === undefined) {
console.info('invalid valueBuckets');
return;
}
let resultNum = valueBuckets.length
let resultNum = valueBuckets.length;
valueBuckets.forEach(vb => {
rdbStore.insert(TBL_NAME, vb, function (err, ret) {
if (callback != undefined) {
if (callback !== undefined) {
callback(err, resultNum);
}
});
......@@ -332,8 +332,8 @@ normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
normalizeUri(uri, callback) {
let err = {"code":0};
let ret = "normalize+" + uri;
let err = {'code':0};
let ret = 'normalize+' + uri;
callback(err, ret);
}
};
......@@ -359,8 +359,8 @@ denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
denormalizeUri(uri, callback) {
let err = {"code":0};
let ret = "denormalize+" + uri;
let err = {'code':0};
let ret = 'denormalize+' + uri;
callback(err, ret);
}
};
......
......@@ -11,7 +11,7 @@ EnvironmentCallback模块提供应用上下文ApplicationContext对系统环境
## 导入模块
```ts
import EnvironmentCallback from "@ohos.application.EnvironmentCallback";
import EnvironmentCallback from '@ohos.application.EnvironmentCallback';
```
......@@ -52,26 +52,26 @@ let callbackId;
export default class EntryAbility extends UIAbility {
onCreate() {
console.log("MyAbility onCreate")
console.log('MyAbility onCreate');
globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = {
onConfigurationUpdated(config){
console.log("onConfigurationUpdated config:" + JSON.stringify(config));
console.log('onConfigurationUpdated config:' + JSON.stringify(config));
},
onMemoryLevel(level){
console.log("onMemoryLevel level:" + level);
console.log('onMemoryLevel level:' + level);
}
}
// 1.获取applicationContext
let applicationContext = globalThis.applicationContext;
// 2.通过applicationContext注册监听应用内生命周期
callbackId = applicationContext.registerEnvironmentCallback(EnvironmentCallback);
console.log("registerEnvironmentCallback number: " + JSON.stringify(callbackId));
console.log('registerEnvironmentCallback number: ' + JSON.stringify(callbackId));
}
onDestroy() {
let applicationContext = globalThis.applicationContext;
applicationContext.unregisterEnvironmentCallback(callbackId, (error, data) => {
console.log("unregisterEnvironmentCallback success, err: " + JSON.stringify(error));
console.log('unregisterEnvironmentCallback success, err: ' + JSON.stringify(error));
});
}
}
......
......@@ -30,7 +30,7 @@ registerErrorObserver(observer: ErrorObserver): number;
```ts
let observer = {
onUnhandledException(errorMsg) {
console.log('onUnhandledException, errorMsg: ', errorMsg)
console.log('onUnhandledException, errorMsg: ', errorMsg);
}
}
errorManager.registerErrorObserver(observer)
......@@ -95,6 +95,6 @@ errorManager.unregisterErrorObserver(observerId)
})
.catch((err) => {
console.log('----------- unregisterErrorObserver fail ----------', err);
})
});
```
\ No newline at end of file
......@@ -35,7 +35,7 @@ createFormBindingData(obj?: Object | string): FormBindingData
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------- | ---- | ------------------------------------------------------------ |
| obj | Object\|string | 否 | js卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。其中图片数据以"formImages"作为标识,内容为图片标识与图片文件描述符的键值对{"formImages": {"key1": fd1, "key2": fd2}} |
| obj | Object\|string | 否 | js卡片要展示的数据。可以是包含若干键值对的Object或者 json 格式的字符串。其中图片数据以'formImages'作为标识,内容为图片标识与图片文件描述符的键值对{'formImages': {'key1': fd1, 'key2': fd2}} |
**返回值:**
......@@ -52,10 +52,10 @@ import formBindingData from '@ohos.application.formBindingData';
import fs from '@ohos.file.fs';
try {
let fd = fs.openSync('/path/to/form.png')
let fd = fs.openSync('/path/to/form.png');
let obj = {
"temperature": "21°",
"formImages": { "image": fd }
'temperature': '21°',
'formImages': { 'image': fd }
};
formBindingData.createFormBindingData(obj);
} catch (error) {
......
......@@ -36,7 +36,7 @@ deleteForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.deleteForm(formId, (error, data) => {
if (error.code) {
console.error('formHost deleteForm, error:' + JSON.stringify(error));
......@@ -71,7 +71,7 @@ deleteForm(formId: string): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.deleteForm(formId).then(() => {
console.log('formHost deleteForm success');
}).catch((error) => {
......@@ -101,7 +101,7 @@ releaseForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.releaseForm(formId, (error, data) => {
if (error.code) {
console.error('formHost releaseForm, error:' + JSON.stringify(error));
......@@ -134,7 +134,7 @@ releaseForm(formId: string, isReleaseCache: boolean, callback: AsyncCallback&lt;
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.releaseForm(formId, true, (error, data) => {
if (error.code) {
console.error('formHost releaseForm, error:' + JSON.stringify(error));
......@@ -172,7 +172,7 @@ releaseForm(formId: string, isReleaseCache?: boolean): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.releaseForm(formId, true).then(() => {
console.log('formHost releaseForm success');
}).catch((error) => {
......@@ -202,7 +202,7 @@ requestForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.requestForm(formId, (error, data) => {
if (error.code) {
console.error('formHost requestForm, error:' + JSON.stringify(error));
......@@ -237,7 +237,7 @@ requestForm(formId: string): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.requestForm(formId).then(() => {
console.log('formHost requestForm success');
}).catch((error) => {
......@@ -267,7 +267,7 @@ castTempForm(formId: string, callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.castTempForm(formId, (error, data) => {
if (error.code) {
console.error('formHost castTempForm, error:' + JSON.stringify(error));
......@@ -302,7 +302,7 @@ castTempForm(formId: string): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.castTempForm(formId).then(() => {
console.log('formHost castTempForm success');
}).catch((error) => {
......@@ -332,7 +332,7 @@ notifyVisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
```ts
import formHost from '@ohos.application.formHost';
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.notifyVisibleForms(formId, (error, data) => {
if (error.code) {
console.error('formHost notifyVisibleForms, error:' + JSON.stringify(error));
......@@ -367,7 +367,7 @@ notifyVisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.notifyVisibleForms(formId).then(() => {
console.log('formHost notifyVisibleForms success');
}).catch((error) => {
......@@ -397,7 +397,7 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;vo
```ts
import formHost from '@ohos.application.formHost';
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.notifyInvisibleForms(formId, (error, data) => {
if (error.code) {
console.error('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
......@@ -432,7 +432,7 @@ notifyInvisibleForms(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.notifyInvisibleForms(formId).then(() => {
console.log('formHost notifyInvisibleForms success');
}).catch((error) => {
......@@ -462,7 +462,7 @@ enableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void&
```ts
import formHost from '@ohos.application.formHost';
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.enableFormsUpdate(formId, (error, data) => {
if (error.code) {
console.error('formHost enableFormsUpdate, error:' + JSON.stringify(error));
......@@ -497,7 +497,7 @@ enableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.enableFormsUpdate(formId).then(() => {
console.log('formHost enableFormsUpdate success');
}).catch((error) => {
......@@ -527,7 +527,7 @@ disableFormsUpdate(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;void
```ts
import formHost from '@ohos.application.formHost';
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.disableFormsUpdate(formId, (error, data) => {
if (error.code) {
console.error('formHost disableFormsUpdate, error:' + JSON.stringify(error));
......@@ -562,7 +562,7 @@ disableFormsUpdate(formIds: Array&lt;string&gt;): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = ["12400633174999288"];
let formId = ['12400633174999288'];
formHost.disableFormsUpdate(formId).then(() => {
console.log('formHost disableFormsUpdate success');
}).catch((error) => {
......@@ -589,7 +589,7 @@ isSystemReady(callback: AsyncCallback&lt;void&gt;): void
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.isSystemReady((error, data) => {
if (error.code) {
console.error('formHost isSystemReady, error:' + JSON.stringify(error));
......@@ -616,7 +616,7 @@ isSystemReady(): Promise&lt;void&gt;
```ts
import formHost from '@ohos.application.formHost';
let formId = "12400633174999288";
let formId = '12400633174999288';
formHost.isSystemReady().then(() => {
console.log('formHost isSystemReady success');
}).catch((error) => {
......@@ -704,7 +704,7 @@ getFormsInfo(bundleName: string, callback: AsyncCallback&lt;Array&lt;formInfo.Fo
```ts
import formHost from '@ohos.application.formHost';
formHost.getFormsInfo("com.example.ohos.formjsdemo", (error, data) => {
formHost.getFormsInfo('com.example.ohos.formjsdemo', (error, data) => {
if (error.code) {
console.error('formHost getFormsInfo, error:' + JSON.stringify(error));
} else {
......@@ -736,7 +736,7 @@ getFormsInfo(bundleName: string, moduleName: string, callback: AsyncCallback&lt;
```ts
import formHost from '@ohos.application.formHost';
formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry", (error, data) => {
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry', (error, data) => {
if (error.code) {
console.error('formHost getFormsInfo, error:' + JSON.stringify(error));
} else {
......@@ -773,7 +773,7 @@ getFormsInfo(bundleName: string, moduleName?: string): Promise&lt;Array&lt;formI
```ts
import formHost from '@ohos.application.formHost';
formHost.getFormsInfo("com.example.ohos.formjsdemo", "entry").then((data) => {
formHost.getFormsInfo('com.example.ohos.formjsdemo', 'entry').then((data) => {
console.log('formHost getFormsInfo, data:' + JSON.stringify(data));
}).catch((error) => {
console.error('formHost getFormsInfo, error:' + JSON.stringify(error));
......@@ -802,7 +802,7 @@ deleteInvalidForms(formIds: Array&lt;string&gt;, callback: AsyncCallback&lt;numb
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds, (error, data) => {
if (error.code) {
console.error('formHost deleteInvalidForms, error:' + JSON.stringify(error));
......@@ -839,7 +839,7 @@ deleteInvalidForms(formIds: Array&lt;string&gt;): Promise&lt;number&gt;
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.deleteInvalidForms(formIds).then((data) => {
console.log('formHost deleteInvalidForms, data:' + JSON.stringify(data));
}).catch((error) => {
......@@ -870,13 +870,13 @@ acquireFormState(want: Want, callback: AsyncCallback&lt;formInfo.FormStateInfo&g
import formHost from '@ohos.application.formHost';
let want = {
"deviceId": "",
"bundleName": "ohos.samples.FormApplication",
"abilityName": "FormAbility",
"parameters": {
"ohos.extra.param.key.module_name": "entry",
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.form_dimension": 2
'deviceId': '',
'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility',
'parameters': {
'ohos.extra.param.key.module_name': 'entry',
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.form_dimension': 2
}
};
formHost.acquireFormState(want, (error, data) => {
......@@ -916,13 +916,13 @@ acquireFormState(want: Want): Promise&lt;formInfo.FormStateInfo&gt;
import formHost from '@ohos.application.formHost';
let want = {
"deviceId": "",
"bundleName": "ohos.samples.FormApplication",
"abilityName": "FormAbility",
"parameters": {
"ohos.extra.param.key.module_name": "entry",
"ohos.extra.param.key.form_name": "widget",
"ohos.extra.param.key.form_dimension": 2
'deviceId': '',
'bundleName': 'ohos.samples.FormApplication',
'abilityName': 'FormAbility',
'parameters': {
'ohos.extra.param.key.module_name': 'entry',
'ohos.extra.param.key.form_name': 'widget',
'ohos.extra.param.key.form_dimension': 2
}
};
formHost.acquireFormState(want).then((data) => {
......@@ -932,9 +932,9 @@ formHost.acquireFormState(want).then((data) => {
});
```
## on("formUninstall")
## on('formUninstall')
on(type: "formUninstall", callback: Callback&lt;string&gt;): void
on(type: 'formUninstall', callback: Callback&lt;string&gt;): void
订阅卡片卸载事件。使用callback异步回调。
......@@ -944,7 +944,7 @@ on(type: "formUninstall", callback: Callback&lt;string&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| type | string | 是 | 填写"formUninstall",表示卡片卸载事件。 |
| type | string | 是 | 填写'formUninstall',表示卡片卸载事件。 |
| callback | Callback&lt;string&gt; | 是 | 回调函数。返回卡片标识。 |
**示例:**
......@@ -954,13 +954,13 @@ import formHost from '@ohos.application.formHost';
let callback = function(formId) {
console.log('formHost on formUninstall, formId:' + formId);
}
formHost.on("formUninstall", callback);
};
formHost.on('formUninstall', callback);
```
## off("formUninstall")
## off('formUninstall')
off(type: "formUninstall", callback?: Callback&lt;string&gt;): void
off(type: 'formUninstall', callback?: Callback&lt;string&gt;): void
取消订阅卡片卸载事件。使用callback异步回调。
......@@ -970,8 +970,8 @@ off(type: "formUninstall", callback?: Callback&lt;string&gt;): void
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------- |
| type | string | 是 | 填写"formUninstall",表示卡片卸载事件。 |
| callback | Callback&lt;string&gt; | 否 | 回调函数。返回卡片标识。缺省时,表示注销所有已注册事件回调。<br> 需与对应on("formUninstall")的callback一致。|
| type | string | 是 | 填写'formUninstall',表示卡片卸载事件。 |
| callback | Callback&lt;string&gt; | 否 | 回调函数。返回卡片标识。缺省时,表示注销所有已注册事件回调。<br> 需与对应on('formUninstall')的callback一致。|
**示例:**
......@@ -980,8 +980,8 @@ import formHost from '@ohos.application.formHost';
let callback = function(formId) {
console.log('formHost on formUninstall, formId:' + formId);
}
formHost.off("formUninstall", callback);
};
formHost.off('formUninstall', callback);
```
## notifyFormsVisible
......@@ -1007,7 +1007,7 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean, callback: A
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsVisible(formIds, true, (error, data) => {
if (error.code) {
console.error('formHost notifyFormsVisible, error:' + JSON.stringify(error));
......@@ -1043,7 +1043,7 @@ notifyFormsVisible(formIds: Array&lt;string&gt;, isVisible: boolean): Promise&lt
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsVisible(formIds, true).then(() => {
console.log('formHost notifyFormsVisible success');
}).catch((error) => {
......@@ -1074,7 +1074,7 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean, c
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsEnableUpdate(formIds, true, (error, data) => {
if (error.code) {
console.error('formHost notifyFormsEnableUpdate, error:' + JSON.stringify(error));
......@@ -1110,7 +1110,7 @@ notifyFormsEnableUpdate(formIds: Array&lt;string&gt;, isEnableUpdate: boolean):
```ts
import formHost from '@ohos.application.formHost';
let formIds = new Array("12400633174999288", "12400633174999289");
let formIds = new Array('12400633174999288', '12400633174999289');
formHost.notifyFormsEnableUpdate(formIds, true).then(() => {
console.log('formHost notifyFormsEnableUpdate success');
}).catch((error) => {
......
......@@ -93,11 +93,11 @@ import formInfo from '@ohos.application.formInfo';
| 名称 | 值 | 说明 |
| ----------- | ---- | ------------ |
| IDENTITY_KEY | "ohos.extra.param.key.form_identity" | 卡片标识。<br>**系统接口**: 此接口为系统接口。 |
| DIMENSION_KEY | "ohos.extra.param.key.form_dimension" | 卡片规格样式。 |
| NAME_KEY | "ohos.extra.param.key.form_name" | 卡片名称。 |
| MODULE_NAME_KEY | "ohos.extra.param.key.module_name" | 卡片所属模块名称。 |
| WIDTH_KEY | "ohos.extra.param.key.form_width" | 卡片宽度。 |
| HEIGHT_KEY | "ohos.extra.param.key.form_height" | 卡片高度。 |
| TEMPORARY_KEY | "ohos.extra.param.key.form_temporary" | 临时卡片。 |
| IDENTITY_KEY | 'ohos.extra.param.key.form_identity' | 卡片标识。<br>**系统接口**: 此接口为系统接口。 |
| DIMENSION_KEY | 'ohos.extra.param.key.form_dimension' | 卡片规格样式。 |
| NAME_KEY | 'ohos.extra.param.key.form_name' | 卡片名称。 |
| MODULE_NAME_KEY | 'ohos.extra.param.key.module_name' | 卡片所属模块名称。 |
| WIDTH_KEY | 'ohos.extra.param.key.form_width' | 卡片宽度。 |
| HEIGHT_KEY | 'ohos.extra.param.key.form_height' | 卡片高度。 |
| TEMPORARY_KEY | 'ohos.extra.param.key.form_temporary' | 临时卡片。 |
......@@ -33,7 +33,7 @@ setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback&l
```ts
import formProvider from '@ohos.app.form.formProvider';
let formId = "12400633174999288";
let formId = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5, (error, data) => {
if (error.code) {
console.log('formProvider setFormNextRefreshTime, error:' + JSON.stringify(error));
......@@ -67,7 +67,7 @@ setFormNextRefreshTime(formId: string, minute: number): Promise&lt;void&gt;
```ts
import formProvider from '@ohos.app.form.formProvider';
let formId = "12400633174999288";
let formId = '12400633174999288';
formProvider.setFormNextRefreshTime(formId, 5).then(() => {
console.log('formProvider setFormNextRefreshTime success');
}).catch((error) => {
......@@ -97,8 +97,8 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let formId = "12400633174999288";
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
formProvider.updateForm(formId, obj, (error, data) => {
if (error.code) {
console.log('formProvider updateForm, error:' + JSON.stringify(error));
......@@ -133,8 +133,8 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
import formBindingData from '@ohos.application.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
let formId = "12400633174999288";
let obj = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
let formId = '12400633174999288';
let obj = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
formProvider.updateForm(formId, obj).then(() => {
console.log('formProvider updateForm success');
}).catch((error) => {
......
......@@ -9,7 +9,7 @@ StaticSubscriberExtensionAbility模块提供静态订阅者ExtensionAbility的
## 导入模块
```ts
import StaticSubscriberExtensionAbility from '@ohos.application.StaticSubscriberExtensionAbility'
import StaticSubscriberExtensionAbility from '@ohos.application.StaticSubscriberExtensionAbility';
```
## StaticSubscriberExtensionAbility.onReceiveEvent
......@@ -33,7 +33,7 @@ onReceiveEvent(event: CommonEventData): void;
```ts
class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility {
onReceiveEvent(event) {
console.log("onReceiveEvent, event: " + JSON.stringify(event))
console.log('onReceiveEvent, event: ' + JSON.stringify(event));
}
}
```
\ No newline at end of file
......@@ -11,7 +11,7 @@ TestRunner模块提供了框架测试的能力。包括准备单元测试环境
## 导入模块
```ts
import TestRunner from '@ohos.application.testRunner'
import TestRunner from '@ohos.application.testRunner';
```
## TestRunner.onPrepare
......@@ -27,7 +27,7 @@ onPrepare(): void
```ts
export default class UserTestRunner implements TestRunner {
onPrepare() {
console.log("Trigger onPrepare")
console.log('Trigger onPrepare');
}
onRun() {}
};
......@@ -49,7 +49,7 @@ onRun(): void
export default class UserTestRunner implements TestRunner {
onPrepare() {}
onRun() {
console.log("Trigger onRun")
console.log('Trigger onRun');
}
};
```
......@@ -14,8 +14,8 @@
```ts
let want = {
bundleName: "com.example.myapp",
abilityName: "MyAbility"
bundleName: 'com.example.myapp',
abilityName: 'MyAbility'
};
let connectOptions = {
......@@ -28,7 +28,7 @@
onFailed(code) {
console.error('onFailed code: ' + code);
}
}
};
let connection = this.context.connectAbility(want, connectOptions);
```
\ No newline at end of file
......@@ -11,7 +11,7 @@
| 名称 | 类型 | 必填| 说明 |
| -------- | -------- | --------| -------- |
| uri | string | 是 | 指示待处理的DataAbility。例:"dataability:///com.example.xxx.xxxx"。 |
| uri | string | 是 | 指示待处理的DataAbility。例:'dataability:///com.example.xxx.xxxx'。 |
| type | featureAbility.DataAbilityOperationType | 是 | 指示数据操作类型。 |
| valuesBucket? | rdb.ValuesBucket | 否 | 指示要操作的数据值。 |
| valueBackReferences? | rdb.ValuesBucket | 否 | 指示包含一组键值对的valuesBucket对象。 |
......
......@@ -11,21 +11,21 @@
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| uri? | string | 否 | 指示待处理的DataAbility。例:"dataability:///com.example.xxx.xxxx"。 |
| uri? | string | 否 | 指示待处理的DataAbility。例:'dataability:///com.example.xxx.xxxx'。 |
| count? | number | 否 | 指示受操作影响的数据数量。 |
**示例:**
```ts
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
// 批量执行数据库操作
function executeBatchOperation() {
let dataAbilityUri = ("dataability:///com.example.myapplication.TestDataAbility");
let dataAbilityUri = ('dataability:///com.example.myapplication.TestDataAbility');
let DAHelper;
try {
DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri);
if (DAHelper == null) {
if (DAHelper === null) {
console.error('DAHelper is null');
return;
}
......@@ -35,9 +35,9 @@ function executeBatchOperation() {
}
let valueBucket = {
"name": "DataAbilityHelperTest",
"age": 24,
"salary": 2024.20,
'name': 'DataAbilityHelperTest',
'age': 24,
'salary': 2024.20,
};
let operations = [
{
......
......@@ -16,24 +16,24 @@
**示例:**
```ts
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
let Want = {
bundleName: "com.example.abilityStartSettingApp2",
abilityName: "com.example.abilityStartSettingApp.EntryAbility",
}
bundleName: 'com.example.abilityStartSettingApp2',
abilityName: 'com.example.abilityStartSettingApp.EntryAbility',
};
let abilityStartSetting ={
[featureAbility.AbilityStartSetting.BOUNDS_KEY] : [100,200,300,400],
[featureAbility.AbilityStartSetting.WINDOW_MODE_KEY] :
featureAbility.AbilityWindowConfiguration.WINDOW_MODE_UNDEFINED,
[featureAbility.AbilityStartSetting.DISPLAY_ID_KEY] : 1,
}
};
let startAbilityParameter = {
want : Want,
abilityStartSetting : abilityStartSetting
}
};
try {
featureAbility.startAbility(startAbilityParameter, (err, data) => {
......@@ -41,6 +41,6 @@ try {
console.log('data : ' + JSON.stringify(data));
});
} catch(error) {
console.log("startAbility error: " + JSON.stringify(error));
console.log('startAbility error: ' + JSON.stringify(error));
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册