未验证 提交 702833ca 编写于 作者: O openharmony_ci 提交者: Gitee

!11459 Fix error sample code of ability

Merge pull request !11459 from yuyaozhi/master
......@@ -43,7 +43,7 @@ updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
| 名称 | 类型 | 必填 | 描述 |
| --------- | ---------------------------------------- | ---- | -------------- |
| config | Configuration | 是 | 新的配置项。 |
| config | [Configuration](js-apis-configuration.md) | 是 | 新的配置项。 |
| callback | AsyncCallback\<void> | 是 | 被指定的回调方法。 |
**示例**
......@@ -74,7 +74,7 @@ updateConfiguration(config: Configuration): Promise\<void>
| 名称 | 类型 | 必填 | 描述 |
| --------- | ---------------------------------------- | ---- | -------------- |
| config | Configuration | 是 | 新的配置项。 |
| config | [Configuration](js-apis-configuration.md) | 是 | 新的配置项。 |
**返回值:**
......
......@@ -11,14 +11,15 @@ Context模块提供开发者运行代码的上下文环境的能力,包括查
通过AbilityContext等继承实现。
```js
import AbilityContext from '@ohos.application.Ability'
class MainAbility extends AbilityContext {
```js
import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
let test = "com.example.test";
let context = this.context.createBundleContext(test);
let test = "com.example.test";
let context = this.context.createBundleContext(test);
}
}
}
```
## 属性
......@@ -65,16 +66,16 @@ createBundleContext(bundleName: string): Context;
**示例:**
```js
import AbilityContext from '@ohos.application.Ability'
class MainAbility extends AbilityContext {
onWindowStageCreate(windowStage) {
let test = "com.example.test";
let context = this.context.createBundleContext(test);
}
}
```js
import Ability from '@ohos.application.Ability'
```
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
let test = "com.example.test";
let context = this.context.createBundleContext(test);
}
}
```
## Context.createModuleContext
......@@ -99,16 +100,16 @@ createModuleContext(moduleName: string): Context;
**示例:**
```js
import AbilityContext from '@ohos.application.Ability'
class MainAbility extends AbilityContext {
onWindowStageCreate(windowStage) {
let moduleName = "module";
let context = this.context.createModuleContext(moduleName);
}
}
```js
import Ability from '@ohos.application.Ability'
```
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
let moduleName = "module";
let context = this.context.createModuleContext(moduleName);
}
}
```
## Context.createModuleContext
......@@ -136,18 +137,17 @@ createModuleContext(bundleName: string, moduleName: string): Context;
**示例:**
```js
import AbilityContext from '@ohos.application.Ability'
class MainAbility extends AbilityContext {
onWindowStageCreate(windowStage) {
let bundleName = "com.example.bundle";
let moduleName = "module";
let context = this.context.createModuleContext(bundleName, moduleName);
}
}
```
```js
import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
let bundleName = "com.example.bundle";
let moduleName = "module";
let context = this.context.createModuleContext(bundleName, moduleName);
}
}
```
## Context.getApplicationContext
......@@ -165,10 +165,15 @@ getApplicationContext(): ApplicationContext;
**示例:**
```js
// 必选项。
let applicationContext = this.context.getApplicationContext();
```
```js
import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
let applicationContext = this.context.getApplicationContext();
}
}
```
## AreaMode
......
......@@ -38,8 +38,9 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>):
```js
import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from '@ohos.ability.wantConstant'
particleAbility.startAbility(
{
{
want:
{
action: "action.system.home",
......@@ -49,11 +50,11 @@ particleAbility.startAbility(
deviceId: "",
bundleName: "com.example.Data",
abilityName: "com.example.Data.MainAbility",
uri:""
uri: ""
},
},
(error, result) => {
console.log('particleAbility startAbility errCode:' + error + 'result:' + result)
console.log('particleAbility startAbility errCode:' + error + 'result:' + result)
},
)
```
......@@ -86,8 +87,9 @@ startAbility(parameter: StartAbilityParameter): Promise\<void>;
```js
import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from '@ohos.ability.wantConstant'
particleAbility.startAbility(
{
{
want:
{
action: "action.system.home",
......@@ -97,7 +99,7 @@ particleAbility.startAbility(
deviceId: "",
bundleName: "com.example.Data",
abilityName: "com.example. Data.MainAbility",
uri:""
uri: ""
},
},
).then((data) => {
......@@ -105,8 +107,6 @@ particleAbility.startAbility(
});
```
## particleAbility.terminateSelf
terminateSelf(callback: AsyncCallback\<void>): void
......@@ -125,15 +125,14 @@ terminateSelf(callback: AsyncCallback\<void>): void
```js
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
terminateSelf(): Promise\<void>
......@@ -152,6 +151,7 @@ terminateSelf(): Promise\<void>
```js
import particleAbility from '@ohos.ability.particleAbility'
particleAbility.terminateSelf().then((data) => {
console.info("particleAbility terminateSelf");
});
......@@ -182,7 +182,8 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
**示例:**
```js
import particleAbility from '@ohos.ability.particleAbility'
import particleAbility from '@ohos.ability.particleAbility'
var uri = "";
particleAbility.acquireDataAbilityHelper(uri)
```
......@@ -375,7 +376,6 @@ particleAbility.cancelBackgroundRunning().then(() => {
```
## particleAbility.connectAbility
connectAbility(request: Want, options:ConnectOptions): number
......@@ -405,37 +405,39 @@ connectAbility(request: Want, options:ConnectOptions): number
**示例**
```js
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)
}
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connectId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
particleAbility.disconnectAbility(connectId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
});
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)
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
});
```
## particleAbility.disconnectAbility
......@@ -455,32 +457,35 @@ disconnectAbility(connection: number, callback:AsyncCallback\<void>): void;
```js
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)
}
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connectId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
var result = particleAbility.disconnectAbility(connectId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
});
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)
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
var result = particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
});
```
......@@ -502,32 +507,36 @@ disconnectAbility(connection: number): Promise\<void>;
```js
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)
}
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connectId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
particleAbility.disconnectAbility(connectId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
});
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)
}
function onFailedCallback(code) {
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
);
particleAbility.disconnectAbility(connId).then((data) => {
console.log(" data: " + data);
}).catch((error) => {
console.log('particleAbilityTest result errCode : ' + error.code)
});
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册