提交 5e92e63c 编写于 作者: Y yuyaozhi

Fix sample code question of ability

Signed-off-by: Nyuyaozhi <yuyaozhi@huawei.com>
上级 9e01c802
......@@ -97,8 +97,8 @@ verifyPermission(permission: string, options: PermissionOptions, callback: Async
import featureAbility from '@ohos.ability.featureAbility'
import bundle from '@ohos.bundle'
var context = featureAbility.getContext();
bundle.getBundleInfo('com.context.test', 1, (datainfo) =>{
context.verifyPermission("com.example.permission", datainfo.uid);
bundle.getBundleInfo('com.context.test', 1, (err,datainfo) =>{
context.verifyPermission("com.example.permission", {uid:datainfo.uid});
});
```
......@@ -153,7 +153,7 @@ verifyPermission(permission: string, options?: PermissionOptions): Promise\<numb
```js
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext();
var Permission = context.PermissionOptions(1,1);
var Permission = {pid:1};
context.verifyPermission('com.context.permission',Permission).then((data) => {
console.info("======================>verifyPermissionCallback====================>");
console.info("====>data====>" + JSON.stringify(data));
......
......@@ -404,10 +404,12 @@ requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: As
**示例:**
```
this.context.requestPermissionsFromUser(permissions,(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
```js
var permissions=['com.example.permission']
this.context.requestPermissionsFromUser(permissions,(result) => {
console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
});
```
......@@ -433,12 +435,14 @@ requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;Permis
**示例:**
```
this.context.requestPermissionsFromUser(permissions).then((data) => {
```js
var permissions=['com.example.permission']
this.context.requestPermissionsFromUser(permissions).then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
```
......
......@@ -4,10 +4,7 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
任务对应的任务快照。
## 导入模块
```
......@@ -18,10 +15,9 @@ import abilitymanager from '@ohos.application.abilityManager';
使用前需要提前引入对应模块。
```
import { ElementName } from '../bundle/elementName';
import { image } from '../@ohos.multimedia.image';
import ElementName from '@ohos.bundle';
import image from '@ohos.multimedia.image';
```
## MissionSnapshot
表示任务对应的任务快照的枚举。
......
......@@ -3,13 +3,10 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Ability模块,提供对Ability生命周期、上下文环境等调用管理。
## 导入模块
```
import Ability from '@ohos.application.Ability';
```
......@@ -200,11 +197,12 @@ onContinue(wantParam : {[key: string]: any}): AbilityConstant.OnContinueResult;
**示例:**
```js
import AbilityConstant from "@ohos.application.AbilityConstant"
class myAbility extends Ability {
onContinue(wantParams) {
console.log('onContinue');
wantParams["myData"] = "my1234567";
return true;
return AbilityConstant.OnContinueResult.AGREE;
}
}
```
......@@ -279,6 +277,7 @@ dump(params: Array\<string>): Array\<string>;
class myAbility extends Ability {
dump(params) {
console.log('dump, params:' + JSON.stringify(params));
return ["params"]
}
}
```
......@@ -316,6 +315,9 @@ call(method: string, data: rpc.Sequenceable): Promise&lt;void&gt;;
```js
import Ability from '@ohos.application.Ability';
class MyMessageAble{ // 自定义的Sequenceable数据结构
name:""
str:""
num: 1
constructor(name, str) {
this.name = name;
this.str = str;
......@@ -386,6 +388,9 @@ callWithResult(method: string, data: rpc.Sequenceable): Promise&lt;rpc.MessagePa
```js
import Ability from '@ohos.application.Ability';
class MyMessageAble{
name:""
str:""
num: 1
constructor(name, str) {
this.name = name;
this.str = str;
......@@ -534,6 +539,9 @@ on(method: string, callback: CaleeCallBack): void;
```js
import Ability from '@ohos.application.Ability';
class MyMessageAble{
name:""
str:""
num: 1
constructor(name, str) {
this.name = name;
this.str = str;
......
......@@ -6,13 +6,15 @@
提供开发者运行代码的上下文环境,包括应用信息、ResourceManager等信息。
## 导入模块
```
import AbilityContext from '@ohos.application.Ability';
```
## 使用说明
通过AbilityContext等继承实现。
## 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
......@@ -55,8 +57,14 @@ createBundleContext(bundleName: string): Context;
**示例:**
```js
let test = "com.example.test";
let context = this.context.createBundleContext(test);
import AbilityContext from '@ohos.application.Ability'
class MainAbility extends AbilityContext {
onWindowStageCreate(windowStage) {
let test = "com.example.test";
let context = this.context.createBundleContext(test);
}
}
```
......
......@@ -6,7 +6,7 @@
## 导入模块
```js
import dataAbilityHelper from "@ohos.ability.dataAbilityHelper";
import featureAbility from "@ohos.ability.featureAbility";
```
## 使用说明
......@@ -14,7 +14,7 @@ import dataAbilityHelper from "@ohos.ability.dataAbilityHelper";
使用前根据具体情况引入如下模块
```
import featureAbility from '@ohos.ability.featureAbility'
import ohos_data_ability from '@ohos.data.dataability'
import ohos_data_ability from '@ohos.data.dataAbility'
import ohos_data_rdb from '@ohos.data.rdb'
```
......
......@@ -22,6 +22,9 @@ import Ability from '@ohos.application.Ability'
```js
import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
func1(){
console.log("func1 is called");
}
onForeground() {
this.context.eventHub.on("123", this.func1);
}
......
......@@ -19,8 +19,9 @@ import abilitymanager from '@ohos.application.abilityManager';
```
```js
import abilitymanager from '@ohos.application.abilityManager';
let upperLimit=1
abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => {
console.log("getExtensionRunningInfos err: " + err + " data: " + JSON.stringify(data));
});
......
......@@ -44,7 +44,7 @@ featureAbility.startAbility(
deviceId: "",
bundleName: "com.example.myapplication",
/* FA模型中abilityName由package + Ability name组成 */
abilityName: "com.example.entry.secondAbility",,
abilityName: "com.example.entry.secondAbility",
uri: ""
},
},
......@@ -139,7 +139,7 @@ startAbilityForResult(parameter: StartAbilityParameter, callback: AsyncCallback\
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbilityForResult(
{
......@@ -157,7 +157,7 @@ featureAbility.startAbilityForResult(
},
},
(err, data) => {
console.info("err: " + JSON.stringfy(err) + "data: " + JSON.stringfy(data))
console.info("err: " + JSON.stringify(err) + "data: " + JSON.stringify(data))
}
)
```
......@@ -185,7 +185,7 @@ startAbilityForResult(parameter: StartAbilityParameter): Promise\<AbilityResult>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.startAbilityForResult(
{
......@@ -291,7 +291,7 @@ terminateSelfWithResult(parameter: AbilityResult): Promise\<void>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant'
featureAbility.terminateSelfWithResult(
{
......@@ -343,7 +343,7 @@ hasWindowFocus(callback: AsyncCallback\<boolean>): void
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.hasWindowFocus()
```
......@@ -391,7 +391,7 @@ getWant(callback: AsyncCallback\<Want>): void
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant()
```
......@@ -414,7 +414,7 @@ getWant(): Promise\<Want>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.getWant().then((data) => {
console.info("==========================>getWantCallBack=======================>");
});
......@@ -437,7 +437,7 @@ getContext(): Context
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
var context = featureAbility.getContext()
context.getBundleName()
```
......@@ -461,7 +461,7 @@ terminateSelf(callback: AsyncCallback\<void>): void
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf()
```
......@@ -484,7 +484,7 @@ terminateSelf(): Promise\<void>
**示例:**
```javascript
import featureAbility from '@ohos.ability.featureability';
import featureAbility from '@ohos.ability.featureAbility';
featureAbility.terminateSelf().then((data) => {
console.info("==========================>terminateSelfCallBack=======================>");
});
......
......@@ -38,12 +38,20 @@ createFormBindingData(obj?: Object | string): FormBindingData
**示例:**
```js
let fd = fileio.openSync(path);
let obj = {
"temperature": "21°",
"formImages": {"image": fd}
};
let formBindingDataObj = formBindingData.createFormBindingData(obj);
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
let context=featureAbility.getContext();
context.getOrCreateLocalDir((err,data)=>{
let path=data+"/xxx.jpg";
let fd = fileio.openSync(path);
let obj = {
"temperature": "21°",
"formImages": {"image": fd}
};
let formBindingDataObj = formBindingData.createFormBindingData(obj);
})
```
## 属性
......
......@@ -46,6 +46,7 @@ onCreate(want: Want): formBindingData.FormBindingData
**示例:**
```js
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onCreate(want) {
console.log('FormExtension onCreate, want:' + want.abilityName);
......@@ -100,6 +101,7 @@ onUpdate(formId: string): void
**示例:**
```js
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + formId);
......@@ -130,6 +132,7 @@ onVisibilityChange(newStatus: { [key: string]: number }): void
**示例:**
```js
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onVisibilityChange(newStatus) {
console.log('FormExtension onVisibilityChange, newStatus:' + newStatus);
......@@ -237,9 +240,11 @@ onAcquireFormState?(want: Want): formInfo.FormState;
**示例:**
```js
import fromInfo from '@ohos.application.fromInfo'
class MyFormExtension extends FormExtension {
onAcquireFormState(want) {
console.log('FormExtension onAcquireFormState, want:' + want);
return fromInfo.FormState.UNKNOWN;
}
}
```
\ No newline at end of file
......@@ -30,10 +30,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData, cal
**示例:**
```js
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2, (data)=>{
console.log('FormExtension context updateForm, data:' + data);
});
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + formId);
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2, (data)=>{
console.log('FormExtension context updateForm, data:' + data);
});
}
}
```
## FormExtensionContext.updateForm
......@@ -59,11 +67,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
**示例:**
```
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2)
.then((data)=>{
console.log('FormExtension context updateForm, data:' + data);
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);});
```js
import formBindingData from '@ohos.application.formBindingData'
export default class MyFormExtension extends FormExtension {
onUpdate(formId) {
console.log('FormExtension onUpdate, formId:' + formId);
let obj2 = formBindingData.createFormBindingData({temperature:"22c", time:"22:00"});
this.context.updateForm(formId, obj2)
.then((data)=>{
console.log('FormExtension context updateForm, data:' + data);
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);});
}
}
```
\ No newline at end of file
......@@ -311,7 +311,7 @@ SystemCapability.Ability.Form
**示例:**
```js
var formId = "12400633174999288";
var formId = ["12400633174999288"];
formHost.notifyVisibleForms(formId, (error, data) => {
if (error.code) {
console.log('formHost notifyVisibleForms, error:' + JSON.stringify(error));
......@@ -344,7 +344,7 @@ SystemCapability.Ability.Form
**示例:**
```js
var formId = "12400633174999288";
var formId = ["12400633174999288"];
formHost.notifyVisibleForms(formId).then(() => {
console.log('formHost notifyVisibleForms success');
}).catch((error) => {
......@@ -372,7 +372,7 @@ SystemCapability.Ability.Form
**示例:**
```js
var formId = "12400633174999288";
var formId = ["12400633174999288"];
formHost.notifyInvisibleForms(formId, (error, data) => {
if (error.code) {
console.log('formHost notifyInvisibleForms, error:' + JSON.stringify(error));
......@@ -405,7 +405,7 @@ SystemCapability.Ability.Form
**示例:**
```js
var formId = "12400633174999288";
var formId = ["12400633174999288"];
formHost.notifyInvisibleForms(formId).then(() => {
console.log('formHost notifyInvisibleForms success');
}).catch((error) => {
......@@ -433,7 +433,7 @@ SystemCapability.Ability.Form
**示例:**
```js
var formId = "12400633174999288";
var formId = ["12400633174999288"];
formHost.enableFormsUpdate(formId, (error, data) => {
if (error.code) {
console.log('formHost enableFormsUpdate, error:' + JSON.stringify(error));
......@@ -466,7 +466,7 @@ SystemCapability.Ability.Form
**示例:**
```js
var formId = "12400633174999288";
var formId = ["12400633174999288"];
formHost.enableFormsUpdate(formId).then(() => {
console.log('formHost enableFormsUpdate success');
}).catch((error) => {
......@@ -494,7 +494,7 @@ SystemCapability.Ability.Form
**示例:**
```js
var formId = "12400633174999288";
var formId = ["12400633174999288"];
formHost.disableFormsUpdate(formId, (error, data) => {
if (error.code) {
console.log('formHost disableFormsUpdate, error:' + JSON.stringify(error));
......@@ -527,7 +527,7 @@ SystemCapability.Ability.Form
**示例:**
```js
var formId = "12400633174999288";
var formId = ["12400633174999288"];
formHost.disableFormsUpdate(formId).then(() => {
console.log('formHost disableFormsUpdate success');
}).catch((error) => {
......
......@@ -4,13 +4,10 @@
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
missionManager模块提供系统任务管理能力,开发者可以对系统任务执行锁定、解锁、清理、切换到前台等操作。
## 导入模块
```
import missionManager from '@ohos.application.missionManager'
```
......@@ -43,10 +40,11 @@ registerMissionListener(listener: MissionListener): number;
```js
var listener = {
onMissionCreated: this.onMissionCreatedCallback,
onMissionDestroyed: this.onMissionDestroyedCallback,
onMissionSnapshotChanged: this.onMissionSnapshotChangedCallback,
onMissionMovedToFront: this.onMissionMovedToFrontCallback
onMissionCreated: function(mission){"--------onMissionCreated-------"},
onMissionDestroyed: function(mission){"--------onMissionDestroyed-------"},
onMissionSnapshotChanged: function(mission){"--------onMissionSnapshotChanged-------"},
onMissionMovedToFront: function(mission){"--------onMissionMovedToFront-------"},
onMissionIconUpdated: function(mission,icon){"--------onMissionIconUpdated-------"}
};
console.log("registerMissionListener")
var listenerid = missionManager.registerMissionListener(listener);
......@@ -73,10 +71,11 @@ unregisterMissionListener(listenerId: number, callback: AsyncCallback&lt;void&gt
```js
var listener = {
onMissionCreated: this.onMissionCreatedCallback,
onMissionDestroyed: this.onMissionDestroyedCallback,
onMissionSnapshotChanged: this.onMissionSnapshotChangedCallback,
onMissionMovedToFront: this.onMissionMovedToFrontCallback
onMissionCreated: function(mission){"--------onMissionCreated-------"},
onMissionDestroyed: function(mission){"--------onMissionDestroyed-------"},
onMissionSnapshotChanged: function(mission){"--------onMissionSnapshotChanged-------"},
onMissionMovedToFront: function(mission){"--------onMissionMovedToFront-------"},
onMissionIconUpdated: function(mission,icon){"--------onMissionIconUpdated-------"}
};
console.log("registerMissionListener")
var listenerid = missionManager.registerMissionListener(listener);
......@@ -111,17 +110,18 @@ unregisterMissionListener(listenerId: number): Promise&lt;void&gt;;
```js
var listener = {
onMissionCreated: this.onMissionCreatedCallback,
onMissionDestroyed: this.onMissionDestroyedCallback,
onMissionSnapshotChanged: this.onMissionSnapshotChangedCallback,
onMissionMovedToFront: this.onMissionMovedToFrontCallback
};
console.log("registerMissionListener")
var listenerid = missionManager.registerMissionListener(listener);
missionManager.unregisterMissionListener(listenerid).catch(function (err){
console.log(err);
});
onMissionCreated: function(mission){"--------onMissionCreated-------"},
onMissionDestroyed: function(mission){"--------onMissionDestroyed-------"},
onMissionSnapshotChanged: function(mission){"--------onMissionSnapshotChanged-------"},
onMissionMovedToFront: function(mission){"--------onMissionMovedToFront-------"},
onMissionIconUpdated: function(mission,icon){"--------onMissionIconUpdated-------"}
};
console.log("registerMissionListener")
var listenerid = missionManager.registerMissionListener(listener);
missionManager.unregisterMissionListener(listenerid).catch(function (err){
console.log(err);
});
```
......@@ -147,15 +147,15 @@ getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback&lt;M
import missionManager from '@ohos.application.missionManager'
var allMissions=missionManager.getMissionInfos("",10).catch(function(err){console.log(err);});
missionManager.getMissionInfo("", allMissions[0].missionId, (error, mission) => {
console.log("getMissionInfo is called, error.code = " + error.code)
console.log("mission.missionId = " + mission.missionId);
console.log("mission.runningState = " + mission.runningState);
console.log("mission.lockedState = " + mission.lockedState);
console.log("mission.timestamp = " + mission.timestamp);
console.log("mission.label = " + mission.label);
console.log("mission.iconPath = " + mission.iconPath);
});
missionManager.getMissionInfo("", allMissions[0].missionId, (error, mission) => {
console.log("getMissionInfo is called, error.code = " + error.code)
console.log("mission.missionId = " + mission.missionId);
console.log("mission.runningState = " + mission.runningState);
console.log("mission.lockedState = " + mission.lockedState);
console.log("mission.timestamp = " + mission.timestamp);
console.log("mission.label = " + mission.label);
console.log("mission.iconPath = " + mission.iconPath);
});
```
......@@ -313,15 +313,17 @@ getMissionSnapShot(deviceId: string, missionId: number): Promise&lt;MissionSnaps
```js
import missionManager from '@ohos.application.missionManager'
var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
console.log(err);
});
console.log("size = " + allMissions.length);
console.log("missions = " + JSON.stringify(allMissions));
var id = allMissions[0].missionId;
var snapshot = missionManager.getMissionSnapShot("", id).catch(function (err){
console.log(err);
});
var allMissions;
missionManager.getMissionInfos("",10).then(function(res){
allMissions=res;
}).catch(function(err){console.log(err);});
console.log("size = " + allMissions.length);
console.log("missions = " + JSON.stringify(allMissions));
var id = allMissions[0].missionId;
var snapshot = missionManager.getMissionSnapShot("", id).catch(function (err){
console.log(err);
});
```
......@@ -382,10 +384,10 @@ lockMission(missionId: number): Promise&lt;void&gt;;
```js
import missionManager from '@ohos.application.missionManager'
var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
console.log(err);
});
var allMissions;
missionManager.getMissionInfos("",10).then(function(res){
allMissions=res;
}).catch(function(err){console.log(err);});
console.log("size = " + allMissions.length);
console.log("missions = " + JSON.stringify(allMissions));
var id = allMissions[0].missionId;
......@@ -454,9 +456,10 @@ unlockMission(missionId: number): Promise&lt;void&gt;;
```js
import missionManager from '@ohos.application.missionManager'
var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
console.log(err);
});
var allMissions;
missionManager.getMissionInfos("",10).then(function(res){
allMissions=res;
}).catch(function(err){console.log(err);});
console.log("size = " + allMissions.length);
console.log("missions = " + JSON.stringify(allMissions));
var id = allMissions[0].missionId;
......@@ -528,9 +531,10 @@ clearMission(missionId: number): Promise&lt;void&gt;;
```js
import missionManager from '@ohos.application.missionManager'
var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
console.log(err);
});
var allMissions;
missionManager.getMissionInfos("",10).then(function(res){
allMissions=res;
}).catch(function(err){console.log(err);});
console.log("size = " + allMissions.length);
console.log("missions = " + JSON.stringify(allMissions));
var id = allMissions[0].missionId;
......@@ -677,9 +681,10 @@ moveMissionToFront(missionId: number, options?: StartOptions): Promise&lt;void&g
```js
import missionManager from '@ohos.application.missionManager'
var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
console.log(err);
});
var allMissions;
missionManager.getMissionInfos("",10).then(function(res){
allMissions=res;
}).catch(function(err){console.log(err);});
console.log("size = " + allMissions.length);
console.log("missions = " + JSON.stringify(allMissions));
var id = allMissions[0].missionId;
......
......@@ -9,7 +9,7 @@
## 导入模块
```js
import ProcessRunningInfo from '@ohos.application.processRunningInfo'
import appManager from '@ohos.application.appManager'
```
## 使用说明
......
......@@ -7,6 +7,12 @@
ServiceExtension的上下文环境,提供ServiceExtension具有的能力和接口,继承自ExtensionContext。
## 导入模块
```
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
```
## startAbility
startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
......@@ -25,13 +31,18 @@ startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void;
**示例:**
```js
let want = {
"bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility"
};
this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringfy(err));
});
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
let want = {
"bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility"};
this.context.startAbility(want, (err) => {
console.log('startAbility result:' + JSON.stringify(err));
});
}
}
```
......@@ -58,15 +69,22 @@ startAbility(want: Want): Promise&lt;void&gt;;
**示例:**
```js
let want = {
"bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility"
};
this.context.startAbility(want).then((data) => {
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
let want = {
"bundleName": "com.example.myapp",
"abilityName": "com.example.myapp.MyAbility"
};
this.context.startAbility(want).then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
```
......@@ -87,9 +105,16 @@ terminateSelf(callback: AsyncCallback&lt;void&gt;): void;
**示例:**
```js
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringfy(err));
});
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
this.context.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
}
```
......@@ -110,11 +135,17 @@ terminateSelf(): Promise&lt;void&gt;;
**示例:**
```js
this.context.terminateSelf(want).then((data) => {
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
this.context.terminateSelf().then((data) => {
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
```
......@@ -173,9 +204,18 @@ disconnectAbility(connection: number, callback:AsyncCallback&lt;void&gt;): void;
**示例:**
```js
this.context.disconnectAbility(connection, (err) => { // connection为connectAbility中的返回值
console.log('terminateSelf result:' + JSON.stringfy(err));
});
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
let connection=1
this.context.disconnectAbility(connection, (err) => {
// connection为connectAbility中的返回值
console.log('terminateSelf result:' + JSON.stringify(err));
});
}
}
```
......@@ -202,11 +242,18 @@ disconnectAbility(connection: number): Promise&lt;void&gt;;
**示例:**
```js
this.context.disconnectAbility(connection).then((data) => { // connection为connectAbility中的返回值
console.log('success:' + JSON.stringfy(data));
}).catch((error) => {
console.log('failed:' + JSON.stringfy(error));
});
import ExtensionContext from '@ohos.application.ServiceExtensionAbility';
class MainAbility extends ExtensionContext {
onWindowStageCreate(windowStage) {
let connection=1
this.context.disconnectAbility(connection).then((data) => { // connection为connectAbility中的返回值
console.log('success:' + JSON.stringify(data));
}).catch((error) => {
console.log('failed:' + JSON.stringify(error));
});
}
}
```
......
......@@ -36,9 +36,11 @@ SystemCapability.Ability.AbilityRuntime.Core
**示例:**
```
```js
import WantConstant from '@ohos.ability.wantConstant';
let accessTokenId =1
let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10"
UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId, (result) => {
UriPermissionManager.verifyUriPermission(uri, WantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId, (result) => {
console.log("result.code = " + result.code)
}) // accessTokenId开发者通过包管理接口自行获取
```
......@@ -70,7 +72,9 @@ SystemCapability.Ability.AbilityRuntime.Core
**示例:**
```
```js
import WantConstant from '@ohos.ability.wantConstant';
let accessTokenId =1
let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10"
UriPermissionManager.verifyUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, accessTokenId)
.then((data) => {
......
......@@ -757,7 +757,7 @@ var wantAgentInfo = {
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
//trigger回调
function triggerCallback(err, data) {
function triggerCallback(data) {
console.info("==========================>triggerCallback=======================>");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册