Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Coping0606
Docs
提交
74984930
D
Docs
项目概览
Coping0606
/
Docs
与 Fork 源项目一致
Fork自
OpenHarmony / Docs
通知
1
Star
1
Fork
0
代码
文件
提交
分支
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
74984930
编写于
10月 22, 2022
作者:
H
HuangXW
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Context错误码整改
Signed-off-by:
N
HuangXW
<
huangxinwei4@huawei.com
>
上级
0e327401
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
2001 addition
and
414 deletion
+2001
-414
zh-cn/application-dev/ability/stage-call.md
zh-cn/application-dev/ability/stage-call.md
+5
-5
zh-cn/application-dev/reference/apis/js-apis-ability-context.md
...application-dev/reference/apis/js-apis-ability-context.md
+993
-143
zh-cn/application-dev/reference/apis/js-apis-application-ability.md
...ication-dev/reference/apis/js-apis-application-ability.md
+216
-137
zh-cn/application-dev/reference/apis/js-apis-extension-context.md
...plication-dev/reference/apis/js-apis-extension-context.md
+2
-2
zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md
...n-dev/reference/apis/js-apis-service-extension-context.md
+785
-127
未找到文件。
zh-cn/application-dev/ability/stage-call.md
浏览文件 @
74984930
...
...
@@ -40,7 +40,7 @@ Caller及Callee功能如下:具体的API详见[接口文档](../reference/apis
|call(method: string, data: rpc.Sequenceable): Promise
\<
void>|向通用组件Callee发送约定序列化数据。|
|callWithResult(method: string, data: rpc.Sequenceable): Promise
\<
rpc.MessageParcel>|向通用组件Callee发送约定序列化数据, 并将Callee返回的约定序列化数据带回。|
|release(): void|释放通用组件的Caller通信接口。|
|on
Release(callback: OnReleaseCallB
ack): void|注册通用组件通信断开监听通知。|
|on
(type: "release", callback: OnReleaseCallb
ack): void|注册通用组件通信断开监听通知。|
## 开发步骤
Call调用的开发步骤:
...
...
@@ -72,7 +72,7 @@ Ability配置标签示例如下:
```
**2. 导入Ability模块**
```
ts
import
Ability
from
'
@ohos.app
lication
.Ability
'
import
Ability
from
'
@ohos.app
.ability
.Ability
'
```
**3. 定义约定的序列化数据**
...
...
@@ -142,7 +142,7 @@ export default class CalleeAbility extends Ability {
### 访问Callee被调用端
**1. 导入Ability模块**
```
ts
import
Ability
from
'
@ohos.app
lication
.Ability
'
import
Ability
from
'
@ohos.app
.ability
.Ability
'
```
**2. 获取Caller通信接口**
...
...
@@ -151,7 +151,7 @@ import Ability from '@ohos.application.Ability'
// 注册caller的release监听
private
regOnRelease
(
caller
)
{
try
{
caller
.
on
Release
(
(
msg
)
=>
{
caller
.
on
(
"
release
"
,
(
msg
)
=>
{
console
.
log
(
`caller onRelease is called
${
msg
}
`
)
})
console
.
log
(
'
caller register OnRelease succeed
'
)
...
...
@@ -192,7 +192,7 @@ async onButtonGetRemoteCaller() {
caller
=
data
console
.
log
(
'
get remote caller success
'
)
// 注册caller的release监听
caller
.
on
Release
(
(
msg
)
=>
{
caller
.
on
(
"
release
"
,
(
msg
)
=>
{
console
.
log
(
`remote caller onRelease is called
${
msg
}
`
)
})
console
.
log
(
'
remote caller register OnRelease succeed
'
)
...
...
zh-cn/application-dev/reference/apis/js-apis-ability-context.md
浏览文件 @
74984930
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-application-ability.md
浏览文件 @
74984930
...
...
@@ -45,7 +45,7 @@ Ability创建时回调,执行初始化业务逻辑操作。
| param | AbilityConstant.LaunchParam | 是 | 创建
ability、上次异常退出的原因信息。 |
**示例:**
```
js
class
myAbility
extends
Ability
{
onCreate
(
want
,
param
)
{
...
...
@@ -320,7 +320,6 @@ onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
通用组件Caller通信客户端调用接口, 用来向通用组件服务端发送约定数据。
## Caller.call
call(method: string, data: rpc.Sequenceable): Promise
<
void
>
;
...
...
@@ -342,54 +341,67 @@ call(method: string, data: rpc.Sequenceable): Promise<void>;
| -------- | -------- |
| Promise
<
void
>
| Promise形式返回应答。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
class
MyMessageAble
{
// 自定义的Sequenceable数据结构
name
:
""
str
:
""
num
:
1
constructor
(
name
,
str
)
{
this
.
name
=
name
;
this
.
str
=
str
;
}
marshalling
(
messageParcel
)
{
messageParcel
.
writeInt
(
this
.
num
);
messageParcel
.
writeString
(
this
.
str
);
console
.
log
(
'
MyMessageAble marshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
}
unmarshalling
(
messageParcel
)
{
this
.
num
=
messageParcel
.
readInt
();
this
.
str
=
messageParcel
.
readString
();
console
.
log
(
'
MyMessageAble unmarshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
}
name
:
""
str
:
""
num
:
1
constructor
(
name
,
str
)
{
this
.
name
=
name
;
this
.
str
=
str
;
}
marshalling
(
messageParcel
)
{
messageParcel
.
writeInt
(
this
.
num
);
messageParcel
.
writeString
(
this
.
str
);
console
.
log
(
'
MyMessageAble marshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
}
unmarshalling
(
messageParcel
)
{
this
.
num
=
messageParcel
.
readInt
();
this
.
str
=
messageParcel
.
readString
();
console
.
log
(
'
MyMessageAble unmarshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
}
};
var
method
=
'
call_Function
'
;
// 约定的通知消息字符串
var
caller
;
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
}).
then
((
obj
)
=>
{
caller
=
obj
;
let
msg
=
new
MyMessageAble
(
1
,
"
world
"
);
// 参考Sequenceable数据定义
caller
.
call
(
method
,
msg
)
.
then
(()
=>
{
console
.
log
(
'
Caller call() called
'
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller call() catch error
'
+
e
);
});
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
});
}
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
}).
then
((
obj
)
=>
{
caller
=
obj
;
let
msg
=
new
MyMessageAble
(
1
,
"
world
"
);
// 参考Sequenceable数据定义
caller
.
call
(
method
,
msg
)
.
then
(()
=>
{
console
.
log
(
'
Caller call() called
'
);
})
.
catch
((
callErr
)
=>
{
console
.
log
(
'
Caller.call catch error, error.code:
'
+
JSON
.
stringify
(
callErr
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
callErr
.
message
));
});
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
}
```
...
...
@@ -415,55 +427,69 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise<rpc.MessagePa
| -------- | -------- |
| Promise
<
rpc.MessageParcel
>
| Promise形式返回通用组件服务端应答数据。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 201 | The application does not have permission to call the interface. |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
class
MyMessageAble
{
name
:
""
str
:
""
num
:
1
constructor
(
name
,
str
)
{
this
.
name
=
name
;
this
.
str
=
str
;
}
marshalling
(
messageParcel
)
{
messageParcel
.
writeInt
(
this
.
num
);
messageParcel
.
writeString
(
this
.
str
);
console
.
log
(
'
MyMessageAble marshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
}
unmarshalling
(
messageParcel
)
{
this
.
num
=
messageParcel
.
readInt
();
this
.
str
=
messageParcel
.
readString
();
console
.
log
(
'
MyMessageAble unmarshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
}
name
:
""
str
:
""
num
:
1
constructor
(
name
,
str
)
{
this
.
name
=
name
;
this
.
str
=
str
;
}
marshalling
(
messageParcel
)
{
messageParcel
.
writeInt
(
this
.
num
);
messageParcel
.
writeString
(
this
.
str
);
console
.
log
(
'
MyMessageAble marshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
}
unmarshalling
(
messageParcel
)
{
this
.
num
=
messageParcel
.
readInt
();
this
.
str
=
messageParcel
.
readString
();
console
.
log
(
'
MyMessageAble unmarshalling num[
'
+
this
.
num
+
'
] str[
'
+
this
.
str
+
'
]
'
);
return
true
;
}
};
var
method
=
'
call_Function
'
;
var
caller
;
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
}).
then
((
obj
)
=>
{
caller
=
obj
;
let
msg
=
new
MyMessageAble
(
1
,
"
world
"
);
caller
.
callWithResult
(
method
,
msg
)
.
then
((
data
)
=>
{
console
.
log
(
'
Caller callWithResult() called
'
);
let
retmsg
=
new
MyMessageAble
(
0
,
""
);
data
.
readSequenceable
(
retmsg
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller callWithResult() catch error
'
+
e
);
});
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
});
}
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
}).
then
((
obj
)
=>
{
caller
=
obj
;
let
msg
=
new
MyMessageAble
(
1
,
"
world
"
);
caller
.
callWithResult
(
method
,
msg
)
.
then
((
data
)
=>
{
console
.
log
(
'
Caller callWithResult() called
'
);
let
retmsg
=
new
MyMessageAble
(
0
,
""
);
data
.
readSequenceable
(
retmsg
);
})
.
catch
((
callErr
)
=>
{
console
.
log
(
'
Caller.callWithResult catch error, error.code:
'
+
JSON
.
stringify
(
callErr
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
callErr
.
message
));
});
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
}
```
...
...
@@ -476,36 +502,48 @@ release(): void;
**系统能力**
:SystemCapability.Ability.AbilityRuntime.AbilityCore
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16200002 | Callee invalid. The callee does not exist. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
var
caller
;
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
}).
then
((
obj
)
=>
{
caller
=
obj
;
try
{
caller
.
release
();
}
catch
(
e
)
{
console
.
log
(
'
Caller Release error
'
+
e
);
}
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
});
}
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
}).
then
((
obj
)
=>
{
caller
=
obj
;
try
{
caller
.
release
();
}
catch
(
releaseErr
)
{
console
.
log
(
'
Caller.release catch error, error.code:
'
+
JSON
.
stringify
(
releaseErr
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
releaseErr
.
message
));
}
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
}
```
## Caller.on
Release
## Caller.on
onRelease(callback: OnReleaseCallB
ack): void;
on(type: "release", callback: OnReleaseCallb
ack): void;
注册通用组件服务端Stub(桩)断开监听通知。
...
...
@@ -515,33 +553,45 @@ onRelease(callback: OnReleaseCallBack): void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 监听releaseCall事件,固定为'release'。 |
| callback | OnReleaseCallBack | 是 | 返回onRelease回调结果。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200001 | Caller released. The caller has been released. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
var
caller
;
export
default
class
MainAbility
extends
Ability
{
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
}).
then
((
obj
)
=>
{
caller
=
obj
;
try
{
caller
.
onRelease
((
str
)
=>
{
console
.
log
(
'
Caller OnRelease CallBack is called
'
+
str
);
});
}
catch
(
e
)
{
console
.
log
(
'
Caller Release error
'
+
e
);
}
console
.
log
(
'
Caller GetCaller Get
'
+
caller
);
}).
catch
((
e
)
=>
{
console
.
log
(
'
Caller GetCaller error
'
+
e
);
});
}
onWindowStageCreate
(
windowStage
)
{
this
.
context
.
startAbilityByCall
({
bundleName
:
"
com.example.myservice
"
,
abilityName
:
"
MainAbility
"
,
deviceId
:
""
}).
then
((
obj
)
=>
{
caller
=
obj
;
try
{
caller
.
on
(
"
release
"
,
(
str
)
=>
{
console
.
log
(
'
Caller OnRelease CallBack is called
'
+
str
);
});
}
catch
(
error
)
{
console
.
log
(
'
Caller.on catch error, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
}
}).
catch
((
err
)
=>
{
console
.
log
(
'
Caller GetCaller error, error.code:
'
+
JSON
.
stringify
(
err
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
err
.
message
));
});
}
}
```
...
...
@@ -550,7 +600,6 @@ onRelease(callback: OnReleaseCallBack): void;
通用组件服务端注册和解除客户端caller通知送信的callback接口。
## Callee.on
on(method: string, callback: CalleeCallBack): void;
...
...
@@ -566,10 +615,20 @@ on(method: string, callback: CalleeCallBack): void;
| method | string | 是 | 与客户端约定的通知消息字符串。 |
| callback | CalleeCallBack | 是 | 一个rpc.MessageParcel类型入参的js通知同步回调函数,
回调函数至少要返回一个空的rpc.Sequenceable数据对象,
其他视为函数执行错误。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200004 | Method registered. The method has registered. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
class
MyMessageAble
{
name
:
""
str
:
""
...
...
@@ -599,14 +658,18 @@ on(method: string, callback: CalleeCallBack): void;
return
new
MyMessageAble
(
10
,
"
Callee test
"
);
}
export
default
class
MainAbility
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
Callee onCreate is called
'
);
this
.
callee
.
on
(
method
,
funcCallBack
);
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
Callee onCreate is called
'
);
try
{
this
.
callee
.
on
(
method
,
funcCallBack
);
}
catch
(
error
)
{
console
.
log
(
'
Callee.on catch error, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
}
}
}
```
## Callee.off
off(method: string): void;
...
...
@@ -621,20 +684,36 @@ off(method: string): void;
| -------- | -------- | -------- | -------- |
| method | string | 是 | 已注册的通知事件字符串。 |
**错误码:**
以下错误码的详细介绍请参见
[
元能力错误码
](
../errorcodes/errorcode-ability.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 401 | Invalid input parameter. |
| 16200005 | Method not registered. The method has not registered. |
| 16000050 | Internal Error. |
**示例:**
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
;
import
Ability
from
'
@ohos.app
.ability
.Ability
'
;
var
method
=
'
call_Function
'
;
export
default
class
MainAbility
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
Callee onCreate is called
'
);
this
.
callee
.
off
(
method
);
onCreate
(
want
,
launchParam
)
{
console
.
log
(
'
Callee onCreate is called
'
);
try
{
this
.
callee
.
off
(
method
);
}
catch
(
error
)
{
console
.
log
(
'
Callee.off catch error, error.code:
'
+
JSON
.
stringify
(
error
.
code
)
+
'
error.message:
'
+
JSON
.
stringify
(
error
.
message
));
}
}
}
```
## OnReleaseCall
B
ack
## OnReleaseCall
b
ack
(msg: string): void;
...
...
@@ -644,7 +723,7 @@ off(method: string): void;
| -------- | -------- | -------- | -------- | -------- |
| (msg: string) | function | 是 | 否 | 调用者注册的侦听器函数接口的原型。 |
## CalleeCall
B
ack
## CalleeCall
b
ack
(indata: rpc.MessageParcel): rpc.Sequenceable;
...
...
zh-cn/application-dev/reference/apis/js-apis-extension-context.md
浏览文件 @
74984930
...
...
@@ -31,7 +31,7 @@ ExtensionContext主要用于查询所属Extension的信息、Module的配置信
三个Module内都定义一个相同名称的ServiceExtension:
```
js
import
ServiceExtension
from
'
@ohos.app
lication
.ServiceExtensionAbility
'
import
ServiceExtension
from
'
@ohos.app
.ability
.ServiceExtensionAbility
'
import
Want
from
'
@ohos.application.Want
'
export
default
class
TheServiceExtension
extends
ServiceExtension
{
onCreate
(
want
:
Want
)
{
...
...
@@ -61,7 +61,7 @@ export default class TheServiceExtension extends ServiceExtension {
在entry的MainAbility的onCreate回调内启动ServiceExtension
```
js
import
Ability
from
'
@ohos.app
lication
.Ability
'
import
Ability
from
'
@ohos.app
.ability
.Ability
'
export
default
class
MainAbility
extends
Ability
{
onCreate
(
want
,
launchParam
)
{
console
.
log
(
"
[Demo] MainAbility onCreate
"
);
...
...
zh-cn/application-dev/reference/apis/js-apis-service-extension-context.md
浏览文件 @
74984930
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录