未验证 提交 951d2859 编写于 作者: O openharmony_ci 提交者: Gitee

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

Merge pull request !1779 from wusongqing/TR1620
......@@ -63,8 +63,8 @@ If this method is called for the first time, a root directory is created.
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getOrCreateLocalDir().then((void) => {
console.info("==========================>getOrCreateLocalDirCallback=======================>");
context.getOrCreateLocalDir().then((data) => {
console.info("data=" + data);
});
```
......@@ -91,9 +91,9 @@ Verifies whether a specific PID and UID have the given permission. This method u
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,8 +146,9 @@ Verifies whether a specific PID and UID have the given permission. This method u
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
var Permission = context.PermissionOptions(1,1);
context.getOrCreateLocalDir('com.context.permission',Permission).then((void) => {
console.info("==========================>verifyPermissionCallback=======================>");
context.verifyPermission('com.context.permission',Permission).then((data) => {
console.info("======================>verifyPermissionCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
......@@ -172,13 +173,16 @@ Requests certain permissions from the system. This method uses a callback to ret
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getOrCreateLocalDir(
context.requestPermissionsFromUser(
["com.example.permission1",
"com.example.permission2",
"com.example.permission3",
"com.example.permission4",
"com.example.permission5"],
1,
1,(err, data)=>{
console.info("====>requestdata====>" + JSON.stringify(data));
console.info("====>requesterrcode====>" + JSON.stringify(err.code));
}
)
```
......@@ -223,8 +227,9 @@ Obtains information about the current application. This method uses a promise to
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getApplicationInfo().then((void) => {
console.info("==========================>getApplicationInfoCallback=======================>");
context.getApplicationInfo().then((data) => {
console.info("=====================>getApplicationInfoCallback===================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
......@@ -269,8 +274,9 @@ Obtains the bundle name of the current ability. This method uses a promise to re
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getBundleName().then((void) => {
console.info("==========================>getBundleNameCallback=======================>");
context.getBundleName().then((data) => {
console.info("=======================>getBundleNameCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
......@@ -315,8 +321,9 @@ Obtains information about the current process, including the PID and process nam
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getProcessInfo().then((void) => {
console.info("==========================>getProcessInfoCallback=======================>");
context.getProcessInfo().then((data) => {
console.info("=======================>getProcessInfoCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
......@@ -365,8 +372,9 @@ This method is available only to Page abilities.
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getElementName().then((void) => {
console.info("==========================>getElementNameCallback=======================>");
context.getElementName().then((data) => {
console.info("=======================>getElementNameCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
......@@ -407,8 +415,9 @@ Obtains the name of the current process. This method uses a promise to return th
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getProcessName().then((void) => {
console.info("==========================>getProcessNameCallback=======================>");
context.getProcessName().then((data) => {
console.info("=======================>getProcessNameCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
......@@ -453,8 +462,9 @@ Obtains the bundle name of the calling ability. This method uses a promise to re
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
context.getCallingBundle().then((void) => {
console.info("==========================>getCallingBundleCallback=======================>");
context.getCallingBundle().then((data) => {
console.info("======================>getCallingBundleCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
});
```
......
......@@ -27,7 +27,6 @@ Obtains the ID attached to the end of a given URI.
**Example**
```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.getIdSync("com.example.dataUriUtils/1221")
```
......@@ -55,10 +54,9 @@ Attaches an ID to the end of a given URI.
**Example**
```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122;
dataUriUtils.attachId(
"com.example.dataUriUtils"
"com.example.dataUriUtils",
idint,
)
```
......@@ -85,7 +83,6 @@ Deletes the ID from the end of a given URI.
**Example**
```js
import dataUriUtils from '@ohos.ability.datauriutils'
dataUriUtils.deleteId("com.example.dataUriUtils/1221")
```
......@@ -112,10 +109,9 @@ Updates the ID in a given URI.
**Example**
```js
import dataUriUtils from '@ohos.ability.datauriutils'
var idint = 1122;
dataUriUtils.updateId(
"com.example.dataUriUtils"
idint,
"com.example.dataUriUtils",
idint
)
```
# ServiceExtensionContext
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......@@ -29,8 +29,8 @@ Starts an ability. This method uses a callback to return the result.
"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 @@ Starts an ability. This method uses a promise to return the result.
};
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 @@ Terminates this ability. This method uses a callback to return the result.
- Example
```
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err);
}
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
......@@ -98,7 +98,7 @@ Terminates this ability. This method uses a promise to return the result.
```
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 @@ Connects this ability to a Service ability.
"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 @@ Disconnects this ability from the Service ability. This method uses a callback t
- Example
```
this.context.disconnectAbility(connection, (err) => { // connection is the return value of connectAbility.
console.log('terminateSelf result:' + JSON.stringfy(err);
}
console.log('terminateSelf result:' + JSON.stringfy(err));
});
```
......@@ -176,7 +176,7 @@ Disconnects this ability from the Service ability. This method uses a promise to
```
this.context.disconnectAbility(connection).then((data) => { // connection is the return value of connectAbility.
console.log('success:' + JSON.stringfy(data));
)).catch((error) => {
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
```
......
# ServiceExtension
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......@@ -39,9 +39,11 @@ Called when an extension is created to initialize the service logic.
- Example
```
class ServiceExt extends ServiceExtension {
onCreate(want) {
console.log('onCreate, want:' + want.abilityName);
}
}
```
......@@ -53,9 +55,10 @@ Called when this extension is destroyed to clear resources.
- Example
```
class ServiceExt extends ServiceExtension {
onDestroy() {
console.log('onDestroy');
destory();
}
}
```
......@@ -74,9 +77,11 @@ Called after **onCreate** is invoked when an ability is started by calling **sta
- Example
```
onRequest(want: Want, startId: number) {
class ServiceExt extends ServiceExtension {
onRequest(want, startId) {
console.log('onRequest, want:' + want.abilityName);
}
}
```
......@@ -106,11 +111,12 @@ Called after **onCreate** is invoked when an ability is started by calling **con
onRemoteRequest(code, data, reply, option) {
}
}
...
class ServiceExt extends ServiceExtension {
onConnect(want) {
console.log('onConnect , want:' + want.abilityName);
return new StubTest("test");
}
}
```
......@@ -127,7 +133,9 @@ Called when the ability is disconnected.
- Example
```
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.
先完成此消息的编辑!
想要评论请 注册