Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
5e92e63c
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5e92e63c
编写于
5月 30, 2022
作者:
Y
yuyaozhi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix sample code question of ability
Signed-off-by:
N
yuyaozhi
<
yuyaozhi@huawei.com
>
上级
9e01c802
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
255 addition
and
151 deletion
+255
-151
zh-cn/application-dev/reference/apis/js-apis-Context.md
zh-cn/application-dev/reference/apis/js-apis-Context.md
+3
-3
zh-cn/application-dev/reference/apis/js-apis-ability-context.md
...application-dev/reference/apis/js-apis-ability-context.md
+9
-5
zh-cn/application-dev/reference/apis/js-apis-application-MissionSnapshot.md
...dev/reference/apis/js-apis-application-MissionSnapshot.md
+2
-6
zh-cn/application-dev/reference/apis/js-apis-application-ability.md
...ication-dev/reference/apis/js-apis-application-ability.md
+12
-4
zh-cn/application-dev/reference/apis/js-apis-application-context.md
...ication-dev/reference/apis/js-apis-application-context.md
+12
-4
zh-cn/application-dev/reference/apis/js-apis-dataAbilityHelper.md
...plication-dev/reference/apis/js-apis-dataAbilityHelper.md
+2
-2
zh-cn/application-dev/reference/apis/js-apis-eventhub.md
zh-cn/application-dev/reference/apis/js-apis-eventhub.md
+3
-0
zh-cn/application-dev/reference/apis/js-apis-extensionrunninginfo.md
...cation-dev/reference/apis/js-apis-extensionrunninginfo.md
+2
-1
zh-cn/application-dev/reference/apis/js-apis-featureAbility.md
.../application-dev/reference/apis/js-apis-featureAbility.md
+11
-11
zh-cn/application-dev/reference/apis/js-apis-formbindingdata.md
...application-dev/reference/apis/js-apis-formbindingdata.md
+14
-6
zh-cn/application-dev/reference/apis/js-apis-formextension.md
...n/application-dev/reference/apis/js-apis-formextension.md
+5
-0
zh-cn/application-dev/reference/apis/js-apis-formextensioncontext.md
...cation-dev/reference/apis/js-apis-formextensioncontext.md
+26
-11
zh-cn/application-dev/reference/apis/js-apis-formhost.md
zh-cn/application-dev/reference/apis/js-apis-formhost.md
+8
-8
zh-cn/application-dev/reference/apis/js-apis-missionManager.md
.../application-dev/reference/apis/js-apis-missionManager.md
+58
-53
zh-cn/application-dev/reference/apis/js-apis-processrunninginfo.md
...lication-dev/reference/apis/js-apis-processrunninginfo.md
+1
-1
zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md
...n-dev/reference/apis/js-apis-service-extension-context.md
+79
-32
zh-cn/application-dev/reference/apis/js-apis-uripermissionmanager.md
...cation-dev/reference/apis/js-apis-uripermissionmanager.md
+7
-3
zh-cn/application-dev/reference/apis/js-apis-wantAgent.md
zh-cn/application-dev/reference/apis/js-apis-wantAgent.md
+1
-1
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-Context.md
浏览文件 @
5e92e63c
...
...
@@ -97,8 +97,8 @@ verifyPermission(permission: string, options: PermissionOptions, callback: Async
import
featureAbility
from
'
@ohos.ability.featureAbility
'
import
bundle
from
'
@ohos.bundle
'
var
context
=
featureAbility
.
getContext
();
bundle
.
getBundleInfo
(
'
com.context.test
'
,
1
,
(
datainfo
)
=>
{
context
.
verifyPermission
(
"
com.example.permission
"
,
datainfo
.
uid
);
bundle
.
getBundleInfo
(
'
com.context.test
'
,
1
,
(
err
,
datainfo
)
=>
{
context
.
verifyPermission
(
"
com.example.permission
"
,
{
uid
:
datainfo
.
uid
}
);
});
```
...
...
@@ -153,7 +153,7 @@ verifyPermission(permission: string, options?: PermissionOptions): Promise\<numb
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
context
=
featureAbility
.
getContext
();
var
Permission
=
context
.
PermissionOptions
(
1
,
1
)
;
var
Permission
=
{
pid
:
1
}
;
context
.
verifyPermission
(
'
com.context.permission
'
,
Permission
).
then
((
data
)
=>
{
console
.
info
(
"
======================>verifyPermissionCallback====================>
"
);
console
.
info
(
"
====>data====>
"
+
JSON
.
stringify
(
data
));
...
...
zh-cn/application-dev/reference/apis/js-apis-ability-context.md
浏览文件 @
5e92e63c
...
...
@@ -404,10 +404,12 @@ requestPermissionsFromUser(permissions: Array<string>, requestCallback: As
**示例:**
```
this.context.requestPermissionsFromUser(permissions,(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
```
js
var
permissions
=
[
'
com.example.permission
'
]
this
.
context
.
requestPermissionsFromUser
(
permissions
,(
result
)
=>
{
console
.
log
(
'
requestPermissionsFromUserresult:
'
+
JSON
.
stringify
(
result
));
});
```
...
...
@@ -433,12 +435,14 @@ requestPermissionsFromUser(permissions: Array<string>) : Promise<Permis
**示例:**
```
this.context.requestPermissionsFromUser(permissions).then((data) => {
```
js
var
permissions
=
[
'
com.example.permission
'
]
this
.
context
.
requestPermissionsFromUser
(
permissions
).
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
});
```
...
...
zh-cn/application-dev/reference/apis/js-apis-application-MissionSnapshot.md
浏览文件 @
5e92e63c
...
...
@@ -4,10 +4,7 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
任务对应的任务快照。
## 导入模块
```
...
...
@@ -18,10 +15,9 @@ import abilitymanager from '@ohos.application.abilityManager';
使用前需要提前引入对应模块。
```
import
{ ElementName } from '../bundle/elementNam
e';
import
{ image } from '../
@ohos.multimedia.image';
import
ElementName from '@ohos.bundl
e';
import
image from '
@ohos.multimedia.image';
```
## MissionSnapshot
表示任务对应的任务快照的枚举。
...
...
zh-cn/application-dev/reference/apis/js-apis-application-ability.md
浏览文件 @
5e92e63c
...
...
@@ -3,13 +3,10 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Ability模块,提供对Ability生命周期、上下文环境等调用管理。
## 导入模块
```
import Ability from '@ohos.application.Ability';
```
...
...
@@ -200,11 +197,12 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
**示例:**
```
js
import
AbilityConstant
from
"
@ohos.application.AbilityConstant
"
class
myAbility
extends
Ability
{
onContinue
(
wantParams
)
{
console
.
log
(
'
onContinue
'
);
wantParams
[
"
myData
"
]
=
"
my1234567
"
;
return
true
;
return
AbilityConstant
.
OnContinueResult
.
AGREE
;
}
}
```
...
...
@@ -279,6 +277,7 @@ dump(params: Array\<string>): Array\<string>;
class
myAbility
extends
Ability
{
dump
(
params
)
{
console
.
log
(
'
dump, params:
'
+
JSON
.
stringify
(
params
));
return
[
"
params
"
]
}
}
```
...
...
@@ -316,6 +315,9 @@ call(method: string, data: rpc.Sequenceable): Promise<void>;
```
js
import
Ability
from
'
@ohos.application.Ability
'
;
class
MyMessageAble
{
// 自定义的Sequenceable数据结构
name
:
""
str
:
""
num
:
1
constructor
(
name
,
str
)
{
this
.
name
=
name
;
this
.
str
=
str
;
...
...
@@ -386,6 +388,9 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise<rpc.MessagePa
```
js
import
Ability
from
'
@ohos.application.Ability
'
;
class
MyMessageAble
{
name
:
""
str
:
""
num
:
1
constructor
(
name
,
str
)
{
this
.
name
=
name
;
this
.
str
=
str
;
...
...
@@ -534,6 +539,9 @@ on(method: string, callback: CaleeCallBack): void;
```
js
import
Ability
from
'
@ohos.application.Ability
'
;
class
MyMessageAble
{
name
:
""
str
:
""
num
:
1
constructor
(
name
,
str
)
{
this
.
name
=
name
;
this
.
str
=
str
;
...
...
zh-cn/application-dev/reference/apis/js-apis-application-context.md
浏览文件 @
5e92e63c
...
...
@@ -6,13 +6,15 @@
提供开发者运行代码的上下文环境,包括应用信息、ResourceManager等信息。
## 导入模块
```
import AbilityContext from '@ohos.application.Ability';
```
## 使用说明
通过AbilityContext等继承实现。
## 属性
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
...
...
@@ -55,8 +57,14 @@ createBundleContext(bundleName: string): Context;
**示例:**
```
js
let
test
=
"
com.example.test
"
;
let
context
=
this
.
context
.
createBundleContext
(
test
);
import
AbilityContext
from
'
@ohos.application.Ability
'
class
MainAbility
extends
AbilityContext
{
onWindowStageCreate
(
windowStage
)
{
let
test
=
"
com.example.test
"
;
let
context
=
this
.
context
.
createBundleContext
(
test
);
}
}
```
...
...
zh-cn/application-dev/reference/apis/js-apis-dataAbilityHelper.md
浏览文件 @
5e92e63c
...
...
@@ -6,7 +6,7 @@
## 导入模块
```
js
import
dataAbilityHelper
from
"
@ohos.ability.dataAbilityHelper
"
;
import
featureAbility
from
"
@ohos.ability.featureAbility
"
;
```
## 使用说明
...
...
@@ -14,7 +14,7 @@ import dataAbilityHelper from "@ohos.ability.dataAbilityHelper";
使用前根据具体情况引入如下模块
```
import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.data
a
bility'
import ohos_data_ability from '@ohos.data.data
A
bility'
import ohos_data_rdb from '@ohos.data.rdb'
```
...
...
zh-cn/application-dev/reference/apis/js-apis-eventhub.md
浏览文件 @
5e92e63c
...
...
@@ -22,6 +22,9 @@ import Ability from '@ohos.application.Ability'
```
js
import
Ability
from
'
@ohos.application.Ability
'
export
default
class
MainAbility
extends
Ability
{
func1
(){
console
.
log
(
"
func1 is called
"
);
}
onForeground
()
{
this
.
context
.
eventHub
.
on
(
"
123
"
,
this
.
func1
);
}
...
...
zh-cn/application-dev/reference/apis/js-apis-extensionrunninginfo.md
浏览文件 @
5e92e63c
...
...
@@ -19,8 +19,9 @@ import abilitymanager from '@ohos.application.abilityManager';
```
```
js
import
abilitymanager
from
'
@ohos.application.abilityManager
'
;
let
upperLimit
=
1
abilitymanager
.
getExtensionRunningInfos
(
upperLimit
,
(
err
,
data
)
=>
{
console
.
log
(
"
getExtensionRunningInfos err:
"
+
err
+
"
data:
"
+
JSON
.
stringify
(
data
));
});
...
...
zh-cn/application-dev/reference/apis/js-apis-featureAbility.md
浏览文件 @
5e92e63c
...
...
@@ -44,7 +44,7 @@ featureAbility.startAbility(
deviceId
:
""
,
bundleName
:
"
com.example.myapplication
"
,
/* FA模型中abilityName由package + Ability name组成 */
abilityName
:
"
com.example.entry.secondAbility
"
,
,
abilityName
:
"
com.example.entry.secondAbility
"
,
uri
:
""
},
},
...
...
@@ -139,7 +139,7 @@ startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.feature
a
bility
'
;
import
featureAbility
from
'
@ohos.ability.feature
A
bility
'
;
import
wantConstant
from
'
@ohos.ability.wantConstant
'
featureAbility
.
startAbilityForResult
(
{
...
...
@@ -157,7 +157,7 @@ featureAbility.startAbilityForResult(
},
},
(
err
,
data
)
=>
{
console
.
info
(
"
err:
"
+
JSON
.
string
fy
(
err
)
+
"
data:
"
+
JSON
.
string
fy
(
data
))
console
.
info
(
"
err:
"
+
JSON
.
string
ify
(
err
)
+
"
data:
"
+
JSON
.
stringi
fy
(
data
))
}
)
```
...
...
@@ -185,7 +185,7 @@ startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.feature
a
bility
'
;
import
featureAbility
from
'
@ohos.ability.feature
A
bility
'
;
import
wantConstant
from
'
@ohos.ability.wantConstant
'
featureAbility
.
startAbilityForResult
(
{
...
...
@@ -291,7 +291,7 @@ terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.feature
a
bility
'
;
import
featureAbility
from
'
@ohos.ability.feature
A
bility
'
;
import
wantConstant
from
'
@ohos.ability.wantConstant
'
featureAbility
.
terminateSelfWithResult
(
{
...
...
@@ -343,7 +343,7 @@ hasWindowFocus(callback: AsyncCallback\<boolean>): void
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.feature
a
bility
'
;
import
featureAbility
from
'
@ohos.ability.feature
A
bility
'
;
featureAbility
.
hasWindowFocus
()
```
...
...
@@ -391,7 +391,7 @@ getWant(callback: AsyncCallback\<Want>): void
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.feature
a
bility
'
;
import
featureAbility
from
'
@ohos.ability.feature
A
bility
'
;
featureAbility
.
getWant
()
```
...
...
@@ -414,7 +414,7 @@ getWant(): Promise\<Want>
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.feature
a
bility
'
;
import
featureAbility
from
'
@ohos.ability.feature
A
bility
'
;
featureAbility
.
getWant
().
then
((
data
)
=>
{
console
.
info
(
"
==========================>getWantCallBack=======================>
"
);
});
...
...
@@ -437,7 +437,7 @@ getContext(): Context
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.feature
a
bility
'
;
import
featureAbility
from
'
@ohos.ability.feature
A
bility
'
;
var
context
=
featureAbility
.
getContext
()
context
.
getBundleName
()
```
...
...
@@ -461,7 +461,7 @@ terminateSelf(callback: AsyncCallback\<void>): void
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.feature
a
bility
'
;
import
featureAbility
from
'
@ohos.ability.feature
A
bility
'
;
featureAbility
.
terminateSelf
()
```
...
...
@@ -484,7 +484,7 @@ terminateSelf(): Promise\<void>
**示例:**
```
javascript
import
featureAbility
from
'
@ohos.ability.feature
a
bility
'
;
import
featureAbility
from
'
@ohos.ability.feature
A
bility
'
;
featureAbility
.
terminateSelf
().
then
((
data
)
=>
{
console
.
info
(
"
==========================>terminateSelfCallBack=======================>
"
);
});
...
...
zh-cn/application-dev/reference/apis/js-apis-formbindingdata.md
浏览文件 @
5e92e63c
...
...
@@ -38,12 +38,20 @@ createFormBindingData(obj?: Object | string): FormBindingData
**示例:**
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
obj
=
{
"
temperature
"
:
"
21°
"
,
"
formImages
"
:
{
"
image
"
:
fd
}
};
let
formBindingDataObj
=
formBindingData
.
createFormBindingData
(
obj
);
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
import
fileio
from
'
@ohos.fileio
'
;
let
context
=
featureAbility
.
getContext
();
context
.
getOrCreateLocalDir
((
err
,
data
)
=>
{
let
path
=
data
+
"
/xxx.jpg
"
;
let
fd
=
fileio
.
openSync
(
path
);
let
obj
=
{
"
temperature
"
:
"
21°
"
,
"
formImages
"
:
{
"
image
"
:
fd
}
};
let
formBindingDataObj
=
formBindingData
.
createFormBindingData
(
obj
);
})
```
## 属性
...
...
zh-cn/application-dev/reference/apis/js-apis-formextension.md
浏览文件 @
5e92e63c
...
...
@@ -46,6 +46,7 @@ onCreate(want: Want): formBindingData.FormBindingData
**示例:**
```
js
import
formBindingData
from
'
@ohos.application.formBindingData
'
export
default
class
MyFormExtension
extends
FormExtension
{
onCreate
(
want
)
{
console
.
log
(
'
FormExtension onCreate, want:
'
+
want
.
abilityName
);
...
...
@@ -100,6 +101,7 @@ onUpdate(formId: string): void
**示例:**
```
js
import
formBindingData
from
'
@ohos.application.formBindingData
'
export
default
class
MyFormExtension
extends
FormExtension
{
onUpdate
(
formId
)
{
console
.
log
(
'
FormExtension onUpdate, formId:
'
+
formId
);
...
...
@@ -130,6 +132,7 @@ onVisibilityChange(newStatus: { [key: string]: number }): void
**示例:**
```
js
import
formBindingData
from
'
@ohos.application.formBindingData
'
export
default
class
MyFormExtension
extends
FormExtension
{
onVisibilityChange
(
newStatus
)
{
console
.
log
(
'
FormExtension onVisibilityChange, newStatus:
'
+
newStatus
);
...
...
@@ -237,9 +240,11 @@ onAcquireFormState?(want: Want): formInfo.FormState;
**示例:**
```
js
import
fromInfo
from
'
@ohos.application.fromInfo
'
class
MyFormExtension
extends
FormExtension
{
onAcquireFormState
(
want
)
{
console
.
log
(
'
FormExtension onAcquireFormState, want:
'
+
want
);
return
fromInfo
.
FormState
.
UNKNOWN
;
}
}
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-formextensioncontext.md
浏览文件 @
5e92e63c
...
...
@@ -30,10 +30,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData, cal
**示例:**
```
js
let
obj2
=
formBindingData
.
createFormBindingData
({
temperature
:
"
22c
"
,
time
:
"
22:00
"
});
this
.
context
.
updateForm
(
formId
,
obj2
,
(
data
)
=>
{
console
.
log
(
'
FormExtension context updateForm, data:
'
+
data
);
});
import
formBindingData
from
'
@ohos.application.formBindingData
'
export
default
class
MyFormExtension
extends
FormExtension
{
onUpdate
(
formId
)
{
console
.
log
(
'
FormExtension onUpdate, formId:
'
+
formId
);
let
obj2
=
formBindingData
.
createFormBindingData
({
temperature
:
"
22c
"
,
time
:
"
22:00
"
});
this
.
context
.
updateForm
(
formId
,
obj2
,
(
data
)
=>
{
console
.
log
(
'
FormExtension context updateForm, data:
'
+
data
);
});
}
}
```
## FormExtensionContext.updateForm
...
...
@@ -59,11 +67,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
**示例:**
```
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2)
.then((data)=>{
console.log('FormExtension context updateForm, data:' + data);
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);});
```
js
import
formBindingData
from
'
@ohos.application.formBindingData
'
export
default
class
MyFormExtension
extends
FormExtension
{
onUpdate
(
formId
)
{
console
.
log
(
'
FormExtension onUpdate, formId:
'
+
formId
);
let
obj2
=
formBindingData
.
createFormBindingData
({
temperature
:
"
22c
"
,
time
:
"
22:00
"
});
this
.
context
.
updateForm
(
formId
,
obj2
)
.
then
((
data
)
=>
{
console
.
log
(
'
FormExtension context updateForm, data:
'
+
data
);
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation updateForm failed. Cause:
'
+
error
);});
}
}
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-formhost.md
浏览文件 @
5e92e63c
...
...
@@ -311,7 +311,7 @@ SystemCapability.Ability.Form
**示例:**
```
js
var
formId
=
"
12400633174999288
"
;
var
formId
=
[
"
12400633174999288
"
]
;
formHost
.
notifyVisibleForms
(
formId
,
(
error
,
data
)
=>
{
if
(
error
.
code
)
{
console
.
log
(
'
formHost notifyVisibleForms, error:
'
+
JSON
.
stringify
(
error
));
...
...
@@ -344,7 +344,7 @@ SystemCapability.Ability.Form
**示例:**
```
js
var
formId
=
"
12400633174999288
"
;
var
formId
=
[
"
12400633174999288
"
]
;
formHost
.
notifyVisibleForms
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost notifyVisibleForms success
'
);
}).
catch
((
error
)
=>
{
...
...
@@ -372,7 +372,7 @@ SystemCapability.Ability.Form
**示例:**
```
js
var
formId
=
"
12400633174999288
"
;
var
formId
=
[
"
12400633174999288
"
]
;
formHost
.
notifyInvisibleForms
(
formId
,
(
error
,
data
)
=>
{
if
(
error
.
code
)
{
console
.
log
(
'
formHost notifyInvisibleForms, error:
'
+
JSON
.
stringify
(
error
));
...
...
@@ -405,7 +405,7 @@ SystemCapability.Ability.Form
**示例:**
```
js
var
formId
=
"
12400633174999288
"
;
var
formId
=
[
"
12400633174999288
"
]
;
formHost
.
notifyInvisibleForms
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost notifyInvisibleForms success
'
);
}).
catch
((
error
)
=>
{
...
...
@@ -433,7 +433,7 @@ SystemCapability.Ability.Form
**示例:**
```
js
var
formId
=
"
12400633174999288
"
;
var
formId
=
[
"
12400633174999288
"
]
;
formHost
.
enableFormsUpdate
(
formId
,
(
error
,
data
)
=>
{
if
(
error
.
code
)
{
console
.
log
(
'
formHost enableFormsUpdate, error:
'
+
JSON
.
stringify
(
error
));
...
...
@@ -466,7 +466,7 @@ SystemCapability.Ability.Form
**示例:**
```
js
var
formId
=
"
12400633174999288
"
;
var
formId
=
[
"
12400633174999288
"
]
;
formHost
.
enableFormsUpdate
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost enableFormsUpdate success
'
);
}).
catch
((
error
)
=>
{
...
...
@@ -494,7 +494,7 @@ SystemCapability.Ability.Form
**示例:**
```
js
var
formId
=
"
12400633174999288
"
;
var
formId
=
[
"
12400633174999288
"
]
;
formHost
.
disableFormsUpdate
(
formId
,
(
error
,
data
)
=>
{
if
(
error
.
code
)
{
console
.
log
(
'
formHost disableFormsUpdate, error:
'
+
JSON
.
stringify
(
error
));
...
...
@@ -527,7 +527,7 @@ SystemCapability.Ability.Form
**示例:**
```
js
var
formId
=
"
12400633174999288
"
;
var
formId
=
[
"
12400633174999288
"
]
;
formHost
.
disableFormsUpdate
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost disableFormsUpdate success
'
);
}).
catch
((
error
)
=>
{
...
...
zh-cn/application-dev/reference/apis/js-apis-missionManager.md
浏览文件 @
5e92e63c
...
...
@@ -4,13 +4,10 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
missionManager模块提供系统任务管理能力,开发者可以对系统任务执行锁定、解锁、清理、切换到前台等操作。
## 导入模块
```
import missionManager from '@ohos.application.missionManager'
```
...
...
@@ -43,10 +40,11 @@ registerMissionListener(listener: MissionListener): number;
```
js
var
listener
=
{
onMissionCreated
:
this
.
onMissionCreatedCallback
,
onMissionDestroyed
:
this
.
onMissionDestroyedCallback
,
onMissionSnapshotChanged
:
this
.
onMissionSnapshotChangedCallback
,
onMissionMovedToFront
:
this
.
onMissionMovedToFrontCallback
onMissionCreated
:
function
(
mission
){
"
--------onMissionCreated-------
"
},
onMissionDestroyed
:
function
(
mission
){
"
--------onMissionDestroyed-------
"
},
onMissionSnapshotChanged
:
function
(
mission
){
"
--------onMissionSnapshotChanged-------
"
},
onMissionMovedToFront
:
function
(
mission
){
"
--------onMissionMovedToFront-------
"
},
onMissionIconUpdated
:
function
(
mission
,
icon
){
"
--------onMissionIconUpdated-------
"
}
};
console
.
log
(
"
registerMissionListener
"
)
var
listenerid
=
missionManager
.
registerMissionListener
(
listener
);
...
...
@@ -73,10 +71,11 @@ unregisterMissionListener(listenerId: number, callback: AsyncCallback<void>
```
js
var
listener
=
{
onMissionCreated
:
this
.
onMissionCreatedCallback
,
onMissionDestroyed
:
this
.
onMissionDestroyedCallback
,
onMissionSnapshotChanged
:
this
.
onMissionSnapshotChangedCallback
,
onMissionMovedToFront
:
this
.
onMissionMovedToFrontCallback
onMissionCreated
:
function
(
mission
){
"
--------onMissionCreated-------
"
},
onMissionDestroyed
:
function
(
mission
){
"
--------onMissionDestroyed-------
"
},
onMissionSnapshotChanged
:
function
(
mission
){
"
--------onMissionSnapshotChanged-------
"
},
onMissionMovedToFront
:
function
(
mission
){
"
--------onMissionMovedToFront-------
"
},
onMissionIconUpdated
:
function
(
mission
,
icon
){
"
--------onMissionIconUpdated-------
"
}
};
console
.
log
(
"
registerMissionListener
"
)
var
listenerid
=
missionManager
.
registerMissionListener
(
listener
);
...
...
@@ -111,17 +110,18 @@ unregisterMissionListener(listenerId: number): Promise<void>;
```
js
var
listener
=
{
onMissionCreated
:
this
.
onMissionCreatedCallback
,
onMissionDestroyed
:
this
.
onMissionDestroyedCallback
,
onMissionSnapshotChanged
:
this
.
onMissionSnapshotChangedCallback
,
onMissionMovedToFront
:
this
.
onMissionMovedToFrontCallback
};
console
.
log
(
"
registerMissionListener
"
)
var
listenerid
=
missionManager
.
registerMissionListener
(
listener
);
missionManager
.
unregisterMissionListener
(
listenerid
).
catch
(
function
(
err
){
console
.
log
(
err
);
});
onMissionCreated
:
function
(
mission
){
"
--------onMissionCreated-------
"
},
onMissionDestroyed
:
function
(
mission
){
"
--------onMissionDestroyed-------
"
},
onMissionSnapshotChanged
:
function
(
mission
){
"
--------onMissionSnapshotChanged-------
"
},
onMissionMovedToFront
:
function
(
mission
){
"
--------onMissionMovedToFront-------
"
},
onMissionIconUpdated
:
function
(
mission
,
icon
){
"
--------onMissionIconUpdated-------
"
}
};
console
.
log
(
"
registerMissionListener
"
)
var
listenerid
=
missionManager
.
registerMissionListener
(
listener
);
missionManager
.
unregisterMissionListener
(
listenerid
).
catch
(
function
(
err
){
console
.
log
(
err
);
});
```
...
...
@@ -147,15 +147,15 @@ getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<M
import
missionManager
from
'
@ohos.application.missionManager
'
var
allMissions
=
missionManager
.
getMissionInfos
(
""
,
10
).
catch
(
function
(
err
){
console
.
log
(
err
);});
missionManager
.
getMissionInfo
(
""
,
allMissions
[
0
].
missionId
,
(
error
,
mission
)
=>
{
console
.
log
(
"
getMissionInfo is called, error.code =
"
+
error
.
code
)
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
);
});
missionManager
.
getMissionInfo
(
""
,
allMissions
[
0
].
missionId
,
(
error
,
mission
)
=>
{
console
.
log
(
"
getMissionInfo is called, error.code =
"
+
error
.
code
)
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
);
});
```
...
...
@@ -313,15 +313,17 @@ getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnaps
```
js
import
missionManager
from
'
@ohos.application.missionManager
'
var
allMissions
=
missionManager
.
getMissionInfos
(
""
,
10
).
catch
(
function
(
err
){
console
.
log
(
err
);
});
console
.
log
(
"
size =
"
+
allMissions
.
length
);
console
.
log
(
"
missions =
"
+
JSON
.
stringify
(
allMissions
));
var
id
=
allMissions
[
0
].
missionId
;
var
snapshot
=
missionManager
.
getMissionSnapShot
(
""
,
id
).
catch
(
function
(
err
){
console
.
log
(
err
);
});
var
allMissions
;
missionManager
.
getMissionInfos
(
""
,
10
).
then
(
function
(
res
){
allMissions
=
res
;
}).
catch
(
function
(
err
){
console
.
log
(
err
);});
console
.
log
(
"
size =
"
+
allMissions
.
length
);
console
.
log
(
"
missions =
"
+
JSON
.
stringify
(
allMissions
));
var
id
=
allMissions
[
0
].
missionId
;
var
snapshot
=
missionManager
.
getMissionSnapShot
(
""
,
id
).
catch
(
function
(
err
){
console
.
log
(
err
);
});
```
...
...
@@ -382,10 +384,10 @@ lockMission(missionId: number): Promise<void>;
```
js
import
missionManager
from
'
@ohos.application.missionManager
'
var
allMissions
=
missionManager
.
getMissionInfos
(
""
,
10
).
catch
(
function
(
err
){
console
.
log
(
err
)
;
});
var
allMissions
;
missionManager
.
getMissionInfos
(
""
,
10
).
then
(
function
(
res
){
allMissions
=
res
;
})
.
catch
(
function
(
err
){
console
.
log
(
err
);})
;
console
.
log
(
"
size =
"
+
allMissions
.
length
);
console
.
log
(
"
missions =
"
+
JSON
.
stringify
(
allMissions
));
var
id
=
allMissions
[
0
].
missionId
;
...
...
@@ -454,9 +456,10 @@ unlockMission(missionId: number): Promise<void>;
```
js
import
missionManager
from
'
@ohos.application.missionManager
'
var
allMissions
=
missionManager
.
getMissionInfos
(
""
,
10
).
catch
(
function
(
err
){
console
.
log
(
err
);
});
var
allMissions
;
missionManager
.
getMissionInfos
(
""
,
10
).
then
(
function
(
res
){
allMissions
=
res
;
}).
catch
(
function
(
err
){
console
.
log
(
err
);});
console
.
log
(
"
size =
"
+
allMissions
.
length
);
console
.
log
(
"
missions =
"
+
JSON
.
stringify
(
allMissions
));
var
id
=
allMissions
[
0
].
missionId
;
...
...
@@ -528,9 +531,10 @@ clearMission(missionId: number): Promise<void>;
```
js
import
missionManager
from
'
@ohos.application.missionManager
'
var
allMissions
=
missionManager
.
getMissionInfos
(
""
,
10
).
catch
(
function
(
err
){
console
.
log
(
err
);
});
var
allMissions
;
missionManager
.
getMissionInfos
(
""
,
10
).
then
(
function
(
res
){
allMissions
=
res
;
}).
catch
(
function
(
err
){
console
.
log
(
err
);});
console
.
log
(
"
size =
"
+
allMissions
.
length
);
console
.
log
(
"
missions =
"
+
JSON
.
stringify
(
allMissions
));
var
id
=
allMissions
[
0
].
missionId
;
...
...
@@ -677,9 +681,10 @@ moveMissionToFront(missionId: number, options?: StartOptions): Promise<void&g
```
js
import
missionManager
from
'
@ohos.application.missionManager
'
var
allMissions
=
missionManager
.
getMissionInfos
(
""
,
10
).
catch
(
function
(
err
){
console
.
log
(
err
);
});
var
allMissions
;
missionManager
.
getMissionInfos
(
""
,
10
).
then
(
function
(
res
){
allMissions
=
res
;
}).
catch
(
function
(
err
){
console
.
log
(
err
);});
console
.
log
(
"
size =
"
+
allMissions
.
length
);
console
.
log
(
"
missions =
"
+
JSON
.
stringify
(
allMissions
));
var
id
=
allMissions
[
0
].
missionId
;
...
...
zh-cn/application-dev/reference/apis/js-apis-processrunninginfo.md
浏览文件 @
5e92e63c
...
...
@@ -9,7 +9,7 @@
## 导入模块
```
js
import
ProcessRunningInfo
from
'
@ohos.application.processRunningInfo
'
import
appManager
from
'
@ohos.application.appManager
'
```
## 使用说明
...
...
zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md
浏览文件 @
5e92e63c
...
...
@@ -7,6 +7,12 @@
ServiceExtension的上下文环境,提供ServiceExtension具有的能力和接口,继承自ExtensionContext。
## 导入模块
```
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
```
## startAbility
startAbility(want: Want, callback: AsyncCallback
<
void
>
): void;
...
...
@@ -25,13 +31,18 @@ startAbility(want: Want, callback: AsyncCallback<void>): void;
**示例:**
```
js
let
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
com.example.myapp.MyAbility
"
};
this
.
context
.
startAbility
(
want
,
(
err
)
=>
{
console
.
log
(
'
startAbility result:
'
+
JSON
.
stringfy
(
err
));
});
import
ExtensionContext
from
'
@ohos.application.ServiceExtensionAbility
'
;
class
MainAbility
extends
ExtensionContext
{
onWindowStageCreate
(
windowStage
)
{
let
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
com.example.myapp.MyAbility
"
};
this
.
context
.
startAbility
(
want
,
(
err
)
=>
{
console
.
log
(
'
startAbility result:
'
+
JSON
.
stringify
(
err
));
});
}
}
```
...
...
@@ -58,15 +69,22 @@ startAbility(want: Want): Promise<void>;
**示例:**
```
js
let
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
com.example.myapp.MyAbility
"
};
this
.
context
.
startAbility
(
want
).
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringfy
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringfy
(
error
));
});
import
ExtensionContext
from
'
@ohos.application.ServiceExtensionAbility
'
;
class
MainAbility
extends
ExtensionContext
{
onWindowStageCreate
(
windowStage
)
{
let
want
=
{
"
bundleName
"
:
"
com.example.myapp
"
,
"
abilityName
"
:
"
com.example.myapp.MyAbility
"
};
this
.
context
.
startAbility
(
want
).
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
});
}
}
```
...
...
@@ -87,9 +105,16 @@ terminateSelf(callback: AsyncCallback<void>): void;
**示例:**
```
js
this
.
context
.
terminateSelf
((
err
)
=>
{
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringfy
(
err
));
});
import
ExtensionContext
from
'
@ohos.application.ServiceExtensionAbility
'
;
class
MainAbility
extends
ExtensionContext
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
terminateSelf
((
err
)
=>
{
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
});
}
}
```
...
...
@@ -110,11 +135,17 @@ terminateSelf(): Promise<void>;
**示例:**
```
js
this
.
context
.
terminateSelf
(
want
).
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringfy
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringfy
(
error
));
});
import
ExtensionContext
from
'
@ohos.application.ServiceExtensionAbility
'
;
class
MainAbility
extends
ExtensionContext
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
terminateSelf
().
then
((
data
)
=>
{
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
});
}
}
```
...
...
@@ -173,9 +204,18 @@ disconnectAbility(connection: number, callback:AsyncCallback<void>): void;
**示例:**
```
js
this
.
context
.
disconnectAbility
(
connection
,
(
err
)
=>
{
// connection为connectAbility中的返回值
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringfy
(
err
));
});
import
ExtensionContext
from
'
@ohos.application.ServiceExtensionAbility
'
;
class
MainAbility
extends
ExtensionContext
{
onWindowStageCreate
(
windowStage
)
{
let
connection
=
1
this
.
context
.
disconnectAbility
(
connection
,
(
err
)
=>
{
// connection为connectAbility中的返回值
console
.
log
(
'
terminateSelf result:
'
+
JSON
.
stringify
(
err
));
});
}
}
```
...
...
@@ -202,11 +242,18 @@ disconnectAbility(connection: number): Promise<void>;
**示例:**
```
js
this
.
context
.
disconnectAbility
(
connection
).
then
((
data
)
=>
{
// connection为connectAbility中的返回值
console
.
log
(
'
success:
'
+
JSON
.
stringfy
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringfy
(
error
));
});
import
ExtensionContext
from
'
@ohos.application.ServiceExtensionAbility
'
;
class
MainAbility
extends
ExtensionContext
{
onWindowStageCreate
(
windowStage
)
{
let
connection
=
1
this
.
context
.
disconnectAbility
(
connection
).
then
((
data
)
=>
{
// connection为connectAbility中的返回值
console
.
log
(
'
success:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
log
(
'
failed:
'
+
JSON
.
stringify
(
error
));
});
}
}
```
...
...
zh-cn/application-dev/reference/apis/js-apis-uripermissionmanager.md
浏览文件 @
5e92e63c
...
...
@@ -36,9 +36,11 @@ SystemCapability.Ability.AbilityRuntime.Core
**示例:**
```
```
js
import
WantConstant
from
'
@ohos.ability.wantConstant
'
;
let
accessTokenId
=
1
let
uri
=
"
fileshare:///com.samples.filesharetest.FileShare/person/10
"
UriPermissionManager.verifyUriPermission(uri,
w
antConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId, (result) => {
UriPermissionManager
.
verifyUriPermission
(
uri
,
W
antConstant
.
Flags
.
FLAG_AUTH_READ_URI_PERMISSION
,
accessTokenId
,
(
result
)
=>
{
console
.
log
(
"
result.code =
"
+
result
.
code
)
})
// accessTokenId开发者通过包管理接口自行获取
```
...
...
@@ -70,7 +72,9 @@ SystemCapability.Ability.AbilityRuntime.Core
**示例:**
```
```
js
import
WantConstant
from
'
@ohos.ability.wantConstant
'
;
let
accessTokenId
=
1
let
uri
=
"
fileshare:///com.samples.filesharetest.FileShare/person/10
"
UriPermissionManager
.
verifyUriPermission
(
uri
,
wantConstant
.
Flags
.
FLAG_AUTH_READ_URI_PERMISSION
,
accessTokenId
)
.
then
((
data
)
=>
{
...
...
zh-cn/application-dev/reference/apis/js-apis-wantAgent.md
浏览文件 @
5e92e63c
...
...
@@ -757,7 +757,7 @@ var wantAgentInfo = {
WantAgent
.
getWantAgent
(
wantAgentInfo
,
getWantAgentCallback
)
//trigger回调
function
triggerCallback
(
err
,
data
)
{
function
triggerCallback
(
data
)
{
console
.
info
(
"
==========================>triggerCallback=======================>
"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录