未验证 提交 2aef369a 编写于 作者: O openharmony_ci 提交者: Gitee

!10031 FeatureAbility和Context接口示例问题修改

Merge pull request !10031 from dy/master
......@@ -94,13 +94,13 @@ export default {
**示例**
```javascript
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
var lifecycleid;
export default class MyAbilityStage extends AbilityStage {
export default class MainAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MainAbility onCreate")
let AbilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
......@@ -139,11 +139,11 @@ export default class MyAbilityStage extends AbilityStage {
// 2.通过applicationContext注册监听应用内生命周期
lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
}
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.unregisterAbilityLifecycleCallback(lifecycleid, (error, data) => {
console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
});
}
}
......
......@@ -128,7 +128,7 @@ let promise = featureAbility.startAbility(
使用OpenHarmony IDL(OpenHarmony Interface Definition Language)来自动生成对应客户端服务端及IRemoteObject代码,具体示例代码和说明请参考:
- [`OpenHarmony IDL`:TS开发步骤](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/IDL/idl-guidelines.md#ts开发步骤)
- [`OpenHarmony IDL`:TS开发步骤](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/IDL/idl-guidelines.md#ts%E5%BC%80%E5%8F%91%E6%AD%A5%E9%AA%A4)
2. 在对应文件编写代码
......@@ -176,7 +176,7 @@ let promise = featureAbility.startAbility(
```javascript
import featureAbility from '@ohos.ability.featureAbility';
let connId = featureAbility.connectAbility(
let connectId = featureAbility.connectAbility(
{
bundleName: "com.jstest.service",
abilityName: "com.jstest.service.ServiceAbility",
......@@ -293,7 +293,7 @@ function getRemoteDeviceId() {
```ts
import featureAbility from '@ohos.ability.featureAbility';
let connId = featureAbility.connectAbility(
let connectId = featureAbility.connectAbility(
{
deviceId: getRemoteDeviceId(),
bundleName: "ohos.samples.etsDemo",
......
......@@ -33,13 +33,13 @@ onConfigurationUpdated(config: Configuration): void;
```js
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
var callbackId;
export default class MyAbilityStage extends AbilityStage {
export default class MyAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MyAbility onCreate")
globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = {
onConfigurationUpdated(config){
......
......@@ -157,11 +157,11 @@ onAbilityContinue(ability: Ability): void;
```js
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
export default class MyAbilityStage extends AbilityStage {
export default class MyAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MyAbility onCreate")
let AbilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
......@@ -200,6 +200,12 @@ onAbilityContinue(ability: Ability): void;
// 2.通过applicationContext注册监听应用内生命周期
let lifecycleid = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleid));
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.unregisterAbilityLifecycleCallback(lifecycleid, (error, data) => {
console.log("unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error));
});
}
}
```
\ No newline at end of file
......@@ -39,13 +39,13 @@ registerAbilityLifecycleCallback(callback: AbilityLifecycleCallback): **number**
**示例:**
```js
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
var lifecycleId;
export default class MyAbilityStage extends AbilityStage {
export default class MyAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MyAbility onCreate")
let AbilityLifecycleCallback = {
onAbilityCreate(ability){
console.log("AbilityLifecycleCallback onAbilityCreate ability:" + JSON.stringify(ability));
......@@ -84,7 +84,7 @@ export default class MyAbilityStage extends AbilityStage {
// 2.通过applicationContext注册监听应用内生命周期
lifecycleId = applicationContext.registerAbilityLifecycleCallback(AbilityLifecycleCallback);
console.log("registerAbilityLifecycleCallback number: " + JSON.stringify(lifecycleId));
}
},
onDestroy() {
let applicationContext = this.context.getApplicationContext();
applicationContext.unregisterAbilityLifecycleCallback(lifecycleId, (error, data) => {
......@@ -144,13 +144,13 @@ registerEnvironmentCallback(callback: EnvironmentCallback): **number**;
**示例:**
```js
import AbilityStage from "@ohos.application.AbilityStage";
import Ability from "@ohos.application.Ability";
var callbackId;
export default class MyAbilityStage extends AbilityStage {
export default class MyAbility extends Ability {
onCreate() {
console.log("MyAbilityStage onCreate")
console.log("MyAbility onCreate")
globalThis.applicationContext = this.context.getApplicationContext();
let EnvironmentCallback = {
onConfigurationUpdated(config){
......
......@@ -14,7 +14,7 @@ FeatureAbility模块的接口只能在Page类型的Ability调用
## 导入模块
```
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility';
```
## featureAbility.startAbility
......@@ -35,8 +35,8 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<number>)
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureAbility'
import wantConstant from '@ohos.ability.wantConstant'
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbility(
{
want:
......@@ -53,7 +53,7 @@ featureAbility.startAbility(
},
},
(err, data) => {
console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
console.info("startAbility err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
}
);
```
......@@ -77,8 +77,8 @@ startAbility(parameter: StartAbilityParameter): Promise\<number>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureAbility'
import wantConstant from '@ohos.ability.wantConstant'
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbility(
{
want:
......@@ -86,7 +86,7 @@ featureAbility.startAbility(
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.myapplication",
/* FA模型中abilityName由package + Ability name组成 */
......@@ -95,7 +95,7 @@ featureAbility.startAbility(
},
}
).then((data) => {
console.info("==========================>startAbility=======================>");
console.info("startAbility data: " + JSON.stringify(data));
});
```
......@@ -122,10 +122,10 @@ acquireDataAbilityHelper(uri: string): DataAbilityHelper
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureAbility'
featureAbility.acquireDataAbilityHelper(
import featureAbility from '@ohos.ability.featureAbility';
var dataAbilityHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
)
);
```
## featureAbility.startAbilityForResult<sup>7+</sup>
......@@ -147,7 +147,7 @@ startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\
```javascript
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbilityForResult(
{
want:
......@@ -164,9 +164,9 @@ featureAbility.startAbilityForResult(
},
},
(err, data) => {
console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
console.info("startAbilityForResult err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
}
)
);
```
## featureAbility.startAbilityForResult<sup>7+</sup>
......@@ -193,7 +193,7 @@ startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.startAbilityForResult(
{
want:
......@@ -221,7 +221,7 @@ featureAbility.startAbilityForResult(
},
},
).then((data) => {
console.info("==========================>startAbilityForResult=======================>");
console.info("startAbilityForResult data: " + JSON.stringify(data));
});
```
......@@ -243,8 +243,8 @@ terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback\<void>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureAbility'
import wantConstant from '@ohos.ability.wantConstant'
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.terminateSelfWithResult(
{
resultCode: 1,
......@@ -301,7 +301,7 @@ terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
import wantConstant from '@ohos.ability.wantConstant';
featureAbility.terminateSelfWithResult(
{
resultCode: 1,
......@@ -351,11 +351,9 @@ hasWindowFocus(callback: AsyncCallback\<boolean>): void
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus(
(err, data) => {
console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
}
)
featureAbility.hasWindowFocus((err, data) => {
console.info("hasWindowFocus err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
## featureAbility.hasWindowFocus<sup>7+<sup>
......@@ -377,7 +375,7 @@ hasWindowFocus(): Promise\<boolean>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus().then((data) => {
console.info("==========================>hasWindowFocus=======================>");
console.info("hasWindowFocus data: " + JSON.stringify(data));
});
```
......@@ -399,11 +397,9 @@ getWant(callback: AsyncCallback\<Want>): void
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant(
(err, data) => {
console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
}
)
featureAbility.getWant((err, data) => {
console.info("getWant err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
## featureAbility.getWant
......@@ -425,7 +421,7 @@ getWant(): Promise\<Want>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant().then((data) => {
console.info("==========================>getWantCallBack=======================>");
console.info("getWant data: " + JSON.stringify(data));
});
```
......@@ -448,7 +444,9 @@ getContext(): Context
```javascript
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext()
context.getBundleName()
context.getBundleName((err, data) => {
console.info("getBundleName err: " + JSON.stringify(err) + "data: " + JSON.stringify(data));
});
```
## featureAbility.terminateSelf<sup>7+</sup>
......@@ -495,7 +493,7 @@ terminateSelf(): Promise\<void>
```javascript
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf().then((data) => {
console.info("==========================>terminateSelfCallBack=======================>");
console.info("==========================>terminateSelf=======================>");
});
```
......@@ -535,8 +533,8 @@ ConnectOptions类型说明
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -546,7 +544,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
......@@ -578,8 +576,8 @@ disconnectAbility(connection: number, callback:AsyncCallback\<void>): void
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -589,7 +587,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -600,7 +598,7 @@ var connId = featureAbility.connectAbility(
onFailed: onFailedCallback,
},
);
var result = featureAbility.disconnectAbility(connId,
var result = featureAbility.disconnectAbility(connectId,
(error) => {
console.log('featureAbilityTest DisConnectJsSameBundleName result errCode : ' + error.code)
},
......@@ -630,8 +628,8 @@ disconnectAbility(connection: number): Promise\<void>
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -641,7 +639,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -653,7 +651,7 @@ var connId = featureAbility.connectAbility(
},
);
featureAbility.disconnectAbility(connId).then((data) => {
featureAbility.disconnectAbility(connectId).then((data) => {
console.log('data : ' + data);
}).catch((error)=>{
console.log('featureAbilityTest result errCode : ' + error.code);
......@@ -678,11 +676,9 @@ getWindow(callback: AsyncCallback\<window.Window>): void
**示例:**
```javascript
featureAbility.getWindow(
(err, data) => {
console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
}
)
featureAbility.getWindow((err, data) => {
console.info("getWindow err: " + JSON.stringify(err) + "data: " + typeof(data));
});
```
## featureAbility.getWindow<sup>7+</sup>
......@@ -703,7 +699,7 @@ getWindow(): Promise\<window.Window>;
```javascript
featureAbility.getWindow().then((data) => {
console.info("=============getWindowPromise========== " + JSON.stringify(data));
console.info("getWindow data: " + typeof(data));
});
```
......@@ -725,8 +721,8 @@ onConnect(elementName: ElementName, remote: rpc.IRemoteObject): void;
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -736,7 +732,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
......@@ -767,8 +763,8 @@ onDisconnect(elementName: ElementName): void;
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -778,7 +774,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
......@@ -809,8 +805,8 @@ ConnectAbility调用失败时的回调函数。
**示例:**
```javascript
import rpc from '@ohos.rpc'
import featureAbility from '@ohos.ability.featureAbility'
import rpc from '@ohos.rpc';
import featureAbility from '@ohos.ability.featureAbility';
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
}
......@@ -820,7 +816,7 @@ function onDisconnectCallback(element){
function onFailedCallback(code){
console.log('featureAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = featureAbility.connectAbility(
var connectId = featureAbility.connectAbility(
{
deviceId: "",
bundleName: "com.ix.ServiceAbility",
......
......@@ -415,7 +415,7 @@ connectAbility(request: Want, options:ConnectOptions): number
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
var connectId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -427,7 +427,7 @@ connectAbility(request: Want, options:ConnectOptions): number
},
);
particleAbility.disconnectAbility(connId).then((data)=>{
particleAbility.disconnectAbility(connectId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
......@@ -464,7 +464,7 @@ import rpc from '@ohos.rpc'
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
var connectId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -475,7 +475,7 @@ import rpc from '@ohos.rpc'
onFailed: onFailedCallback,
},
);
var result = particleAbility.disconnectAbility(connId).then((data)=>{
var result = particleAbility.disconnectAbility(connectId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
......@@ -511,7 +511,7 @@ function onConnectCallback(element, remote){
function onFailedCallback(code){
console.log('particleAbilityTest ConnectAbility onFailed errCode : ' + code)
}
var connId = particleAbility.connectAbility(
var connectId = particleAbility.connectAbility(
{
bundleName: "com.ix.ServiceAbility",
abilityName: "ServiceAbilityA",
......@@ -523,7 +523,7 @@ function onConnectCallback(element, remote){
},
);
particleAbility.disconnectAbility(connId).then((data)=>{
particleAbility.disconnectAbility(connectId).then((data)=>{
console.log( " data: " + data);
}).catch((error)=>{
console.log('particleAbilityTest result errCode : ' + error.code )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册