未验证 提交 69c02c65 编写于 作者: O openharmony_ci 提交者: Gitee

!1620 修改老的文档示例代码

Merge pull request !1620 from 刘宝/master
......@@ -63,7 +63,7 @@ getOrCreateLocalDir(): Promise\<string>
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getOrCreateLocalDir().then((void) => {
context.getOrCreateLocalDir().then(() => {
console.info("==========================>getOrCreateLocalDirCallback=======================>");
});
```
......@@ -91,9 +91,9 @@ verifyPermission(permission: string, options: PermissionOptions, callback: Async
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle'
var context = featureAbility.getContext();
var datainfo = await bundle.getBundleInfo('com.context.test',1);
context.verifyPermission("com.example.permission",datainfo.uid)
bundle.getBundleInfo('com.context.test', 1, (datainfo) =>{
context.verifyPermission("com.example.permission", datainfo.uid);
});
```
......@@ -146,7 +146,7 @@ verifyPermission(permission: string, options?: PermissionOptions): Promise\<numb
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
var Permission = context.PermissionOptions(1,1);
context.getOrCreateLocalDir('com.context.permission',Permission).then((void) => {
context.getOrCreateLocalDir('com.context.permission',Permission).then(() => {
console.info("==========================>verifyPermissionCallback=======================>");
});
```
......@@ -223,7 +223,7 @@ getApplicationInfo(): Promise\<ApplicationInfo>
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getApplicationInfo().then((void) => {
context.getApplicationInfo().then(() => {
console.info("==========================>getApplicationInfoCallback=======================>");
});
```
......@@ -269,7 +269,7 @@ getBundleName(): Promise\<string>
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getBundleName().then((void) => {
context.getBundleName().then(() => {
console.info("==========================>getBundleNameCallback=======================>");
});
```
......@@ -315,7 +315,7 @@ getProcessInfo(): Promise\<ProcessInfo>
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getProcessInfo().then((void) => {
context.getProcessInfo().then(() => {
console.info("==========================>getProcessInfoCallback=======================>");
});
```
......@@ -365,7 +365,7 @@ getElementName(): Promise\<ElementName>
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getElementName().then((void) => {
context.getElementName().then(() => {
console.info("==========================>getElementNameCallback=======================>");
});
```
......@@ -407,7 +407,7 @@ getProcessName(): Promise\<string>
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getProcessName().then((void) => {
context.getProcessName().then(() => {
console.info("==========================>getProcessNameCallback=======================>");
});
```
......@@ -453,7 +453,7 @@ getCallingBundle(): Promise\<string>
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getCallingBundle().then((void) => {
context.getCallingBundle().then(() => {
console.info("==========================>getCallingBundleCallback=======================>");
});
```
......
......@@ -27,7 +27,6 @@ getId(uri: string): number
**示例:**
```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.getIdSync("com.example.dataUriUtils/1221")
```
......@@ -55,10 +54,9 @@ attachId(uri: string, id: number): string
**示例:**
```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122;
dataUriUtils.attachId(
"com.example.dataUriUtils"
"com.example.dataUriUtils",
idint,
)
```
......@@ -85,7 +83,6 @@ deleteId(uri: string): string
**示例:**
```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.deleteId("com.example.dataUriUtils/1221")
```
......@@ -112,11 +109,10 @@ updateId(uri: string, id: number): string
**示例:**
```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122;
dataUriUtils.updateId(
"com.example.dataUriUtils"
idint,
"com.example.dataUriUtils",
idint
)
```
......@@ -137,8 +137,8 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
- 示例:
```
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err);
}
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
......@@ -157,7 +157,7 @@ terminateSelf(): Promise&lt;void&gt;;
```
this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data));
)).catch((error) => {
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
......
......@@ -65,8 +65,8 @@ var DAHelper = featureAbility.acquireDataAbilityHelper(
);
var mode = "rwt";
DAHelper.openFile(
"dataability:///com.example.DataAbility"
mode).then((void) => {
"dataability:///com.example.DataAbility",
mode).then((data) => {
console.info("==========================>openFileCallback=======================>");
});
```
......@@ -338,7 +338,7 @@ var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
DAHelper.denormalizeUri(
"dataability:///com.example.DataAbility",,
"dataability:///com.example.DataAbility",
(err, data) => {
console.info("==========================>Called=======================>");
});
......@@ -398,7 +398,7 @@ var helper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
helper.notifyChange(
"dataability:///com.example.DataAbility",,
"dataability:///com.example.DataAbility",
(err) => {
console.info("==========================>Called=======================>");
});
......@@ -430,7 +430,7 @@ var DAHelper = featureAbility.acquireDataAbilityHelper(
);
DAHelper.notifyChange(
"dataability:///com.example.DataAbility",
).then((void) => {
).then(() => {
console.info("==========================>notifyChangeCallback=======================>");
});
```
......@@ -747,7 +747,7 @@ import ohos_data_ability from '@ohos.data.dataability'
var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
var cars=new Array({"value1"}, {"value2"}, {"value3"}, {"value4"});
var cars=new Array("value1", "value2", "value3", "value4");
let da = new ohos_data_ability.DataAbilityPredicates()
DAHelper.query(
"dataability:///com.example.DataAbility",
......@@ -787,7 +787,7 @@ import ohos_data_ability from '@ohos.data.dataability'
var DAHelper = featureAbility.acquireDataAbilityHelper(
"dataability:///com.example.DataAbility"
);
var cars=new Array({"value1"}, {"value2"}, {"value3"}, {"value4"});
var cars=new Array("value1", "value2", "value3", "value4");
let da = new ohos_data_ability.DataAbilityPredicates()
DAHelper.query(
"dataability:///com.example.DataAbility",
......
......@@ -28,6 +28,7 @@ startAbility(parameter: StartAbilityParameter, callback: AsyncCallback\<void>: v
```js
import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from "@ohos.ability.wantConstant"
particleAbility.startAbility(
{
want:
......@@ -35,7 +36,7 @@ particleAbility.startAbility(
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
flags: FLAG_AUTH_READ_URI_PERMISSION;
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.Data",
abilityName: "com.example.Data.MainAbility",
......@@ -70,6 +71,7 @@ startAbility(parameter: StartAbilityParameter): Promise\<number>
```js
import particleAbility from '@ohos.ability.particleAbility'
import wantConstant from "@ohos.ability.wantConstant"
particleAbility.startAbility(
{
want:
......@@ -77,14 +79,14 @@ particleAbility.startAbility(
action: "action.system.home",
entities: ["entity.system.home"],
type: "MIMETYPE",
flags: FLAG_AUTH_READ_URI_PERMISSION;
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
deviceId: "",
bundleName: "com.example.Data",
abilityName: "com.example.Data.MainAbility",
abilityName: "com.example. Data.MainAbility",
uri:""
},
},
).then((void) => {
).then(() => {
console.info("particleAbility startAbility");
});
```
......@@ -131,7 +133,7 @@ terminateSelf(): Promise\<void>
```js
import particleAbility from '@ohos.ability.particleAbility'
particleAbility.terminateSelf().then((void) => {
particleAbility.terminateSelf().then(() => {
console.info("particleAbility terminateSelf");
});
```
......@@ -195,7 +197,7 @@ connectAbility(request: Want, options:ConnectOptions): number
```javascript
import particleAbility from '@ohos.ability.particleAbility'
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
console.log('ConnectAbility onConnectCallback');
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
......@@ -234,7 +236,7 @@ disconnectAbility(connection: number, callback:AsyncCallback\<void>): void
```javascript
import particleAbility from '@ohos.ability.particleAbility'
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
console.log('ConnectAbility onConnectCallback');
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
......@@ -255,8 +257,8 @@ var connId = particleAbility.connectAbility(
);
var result = particleAbility.disconnectAbility(connId,
(error,data) => {
console.log('particleAbilityTest DisConnectAbility result errCode : ' + error.code + " data: " + data)
},
console.log('particleAbilityTest DisConnectAbility result errCode : ' + error.code + " data: " + data);
}
);
```
......@@ -282,7 +284,7 @@ disconnectAbility(connection: number): Promise\<void>
```javascript
import particleAbility from '@ohos.ability.particleAbility'
function onConnectCallback(element, remote){
console.log('ConnectAbility onConnect remote is proxy:' + (remote instanceof rpc.RemoteProxy));
console.log('ConnectAbility onConnect onConnectCallback');
}
function onDisconnectCallback(element){
console.log('ConnectAbility onDisconnect element.deviceId : ' + element.deviceId)
......@@ -301,7 +303,7 @@ var connId = particleAbility.connectAbility(
onFailed: onFailedCallback,
},
);
var result = particleAbility.disconnectAbility(connId).then((void) => {
var result = particleAbility.disconnectAbility(connId).then(() => {
console.info("particleAbilityTest disconnectAbility");
});
```
......
......@@ -29,8 +29,8 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
"abilityName": "com.example.myapp.MyAbility"
};
this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringfy(err);
}
console.log('startAbility result:' + JSON.stringfy(err));
});
```
......@@ -58,7 +58,7 @@ startAbility(want: Want): Promise&lt;void&gt;;
};
this.context.startAbility(want).then((data) => {
console.log('success:' + JSON.stringfy(data));
)).catch((error) => {
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
......@@ -78,8 +78,8 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
- 示例:
```
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err);
}
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
......@@ -98,7 +98,7 @@ terminateSelf(): Promise&lt;void&gt;;
```
this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data));
)).catch((error) => {
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
......@@ -128,8 +128,8 @@ connectAbility(want: Want, options: ConnectOptions): number;
"abilityName": "com.example.myapp.MyAbility"
};
let options = {
onConnect: function(elementName, proxy) {}
onDisConnect: function(elementName) {}
onConnect: function(elementName, proxy) {},
onDisConnect: function(elementName) {},
onFailed: function(code) {}
}
let connection = this.context.connectAbility(want,options);
......@@ -151,8 +151,8 @@ disconnectAbility(connection: number, callback:AsyncCallback&lt;void&gt;): void;
- 示例:
```
this.context.disconnectAbility(connection, (err) => { // connection为connectAbility中的返回值
console.log('terminateSelf result:' + JSON.stringfy(err);
}
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
......@@ -176,7 +176,7 @@ disconnectAbility(connection: number): Promise&lt;void&gt;;
```
this.context.disconnectAbility(connection).then((data) => { // connection为connectAbility中的返回值
console.log('success:' + JSON.stringfy(data));
)).catch((error) => {
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
......
......@@ -39,8 +39,10 @@ Extension生命周期回调,在创建时回调,执行初始化业务逻辑
- 示例:
```
onCreate(want) {
class ServiceExt extends ServiceExtension {
onCreate(want) {
console.log('onCreate, want:' + want.abilityName);
}
}
```
......@@ -53,9 +55,10 @@ Extension生命周期回调,在销毁时回调,执行资源清理等操作
- 示例:
```
onDestroy() {
class ServiceExt extends ServiceExtension {
onDestroy() {
console.log('onDestroy');
destory();
}
}
```
......@@ -74,8 +77,10 @@ Extension生命周期回调,如果是startAbility拉起的服务,会在onCre
- 示例:
```
onRequest(want: Want, startId: number) {
class ServiceExt extends ServiceExtension {
onRequest(want, startId) {
console.log('onRequest, want:' + want.abilityName);
}
}
```
......@@ -106,10 +111,11 @@ Extension生命周期回调,如果是connectAbility拉起的服务,会在onC
onRemoteRequest(code, data, reply, option) {
}
}
...
onConnect(want) {
class ServiceExt extends ServiceExtension {
onConnect(want) {
console.log('onConnect , want:' + want.abilityName);
return new StubTest("test");
}
}
```
......@@ -127,7 +133,9 @@ Extension的生命周期,断开服务连接时回调。
- 示例:
```
onDisconnect(want) {
class ServiceExt extends ServiceExtension {
onDisconnect(want) {
console.log('onDisconnect, want:' + want.abilityName);
}
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册