From 2133792a1852f27b93816865165a41e233509bf9 Mon Sep 17 00:00:00 2001 From: fanchenxuan Date: Fri, 16 Sep 2022 14:57:19 +0800 Subject: [PATCH] =?UTF-8?q?docs=E4=B8=80=E8=87=B4=E6=80=A7=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fanchenxuan --- .../apis/js-apis-abilityAccessCtrl.md | 8 +- .../reference/apis/js-apis-privacyManager.md | 132 ++++++++++-------- 2 files changed, 76 insertions(+), 64 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-abilityAccessCtrl.md b/zh-cn/application-dev/reference/apis/js-apis-abilityAccessCtrl.md index 6f0790203a..2b2f0e6444 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-abilityAccessCtrl.md +++ b/zh-cn/application-dev/reference/apis/js-apis-abilityAccessCtrl.md @@ -339,8 +339,8 @@ function OnPermissionStateChanged(data){ } let atManager = abilityAccessCtrl.createAtManager(); let type: 'permissionStateChange' = 'permissionStateChange'; -let tokenIDList: Array<number> = []; -let permissionNameList: Array<string> = []; +let tokenIDList: Array = []; +let permissionNameList: Array = []; try{ atManager.on(type, tokenIDList, permissionNameList, OnPermissionStateChanged); } @@ -377,8 +377,8 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; let atManager = abilityAccessCtrl.createAtManager(); let type: 'permissionStateChange' = 'permissionStateChange'; -let tokenIDList: Array<number> = []; -let permissionNameList: Array<string> = []; +let tokenIDList: Array = []; +let permissionNameList: Array = []; try{ atManager.off(type, tokenIDList, permissionNameList); } diff --git a/zh-cn/application-dev/reference/apis/js-apis-privacyManager.md b/zh-cn/application-dev/reference/apis/js-apis-privacyManager.md index edb3da9da7..140591d459 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-privacyManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-privacyManager.md @@ -45,13 +45,15 @@ addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: n import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -let bundleName = "com.ohos.permissionmanager"; // change to your bundle name -let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - -var tokenID = appInfo.accessTokenId; // 可以通过getApplicationInfo获取accessTokenId -privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0).then(data => { - console.log(`promise: data->${JSON.stringify(data)}`); -}); +async addPermissionUsedRecord() { + let bundleName = "com.ohos.permissionmanager"; // change to your bundle name + let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function + + var tokenID = appInfo.accessTokenId; // 可以通过getApplicationInfo获取accessTokenId + privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0).then(data => { + console.log(`promise: data->${JSON.stringify(data)}`); + }); +} ``` ## privacyManager.addPermissionUsedRecord @@ -81,13 +83,15 @@ addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: n import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -let bundleName = "com.ohos.permissionmanager"; // change to your bundle name -let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - -var tokenID = appInfo.accessTokenId; // 可以通过getApplicationInfo获取accessTokenId -privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0, (err, data) => { - console.log(`callback: data->${JSON.stringify(data)}`); -}); +async addPermissionUsedRecord() { + let bundleName = "com.ohos.permissionmanager"; // change to your bundle name + let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function + + var tokenID = appInfo.accessTokenId; // 可以通过getApplicationInfo获取accessTokenId + privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0, (err, data) => { + console.log(`callback: data->${JSON.stringify(data)}`); + }); +} ``` ## privacyManager.getPermissionUsedRecords @@ -194,16 +198,18 @@ startUsingPermission(tokenID: number, permissionName: string): Promise<number import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -let bundleName = "com.ohos.permissionmanager"; // change to your bundle name -let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - -let tokenID = appInfo.accessTokenId; -let permissionName = "ohos.permission.CAMERA"; -privacyManager.startUsingPermission(tokenID, permissionName).then(data => { - console.log(`promise: data->${JSON.stringify(data)}`); -}).catch(err => { - console.log(`Error: err->${JSON.stringify(err)}`); -}); +async startUsingPermission() { + let bundleName = "com.ohos.permissionmanager"; // change to your bundle name + let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function + + let tokenID = appInfo.accessTokenId; + let permissionName = "ohos.permission.CAMERA"; + privacyManager.startUsingPermission(tokenID, permissionName).then(data => { + console.log(`promise: data->${JSON.stringify(data)}`); + }).catch(err => { + console.log(`Error: err->${JSON.stringify(err)}`); + }); +} ``` ## privacyManager.startUsingPermission9+ @@ -230,18 +236,20 @@ startUsingPermission(tokenID: number, permissionName: string, callback: AsyncCal import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -let bundleName = "com.ohos.permissionmanager"; // change to your bundle name -let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - -let tokenID = appInfo.accessTokenId; -let permissionName = "ohos.permission.CAMERA"; -privacyManager.startUsingPermission(tokenID, permissionName, (err, data)=> { - if (err) { - console.log(`Error: err->${JSON.stringify(err)}`); - } else { - console.log(`promise: data->${JSON.stringify(data)}`); - } -}); +async startUsingPermission() { + let bundleName = "com.ohos.permissionmanager"; // change to your bundle name + let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function + + let tokenID = appInfo.accessTokenId; + let permissionName = "ohos.permission.CAMERA"; + privacyManager.startUsingPermission(tokenID, permissionName, (err, data)=> { + if (err) { + console.log(`Error: err->${JSON.stringify(err)}`); + } else { + console.log(`promise: data->${JSON.stringify(data)}`); + } + }); +} ``` ## privacyManager.stopUsingPermission9+ @@ -273,16 +281,18 @@ stopUsingPermission(tokenID: number, permissionName: string): Promise<number& import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -let bundleName = "com.ohos.permissionmanager"; // change to your bundle name -let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - -let tokenID = appInfo.accessTokenId; -let permissionName = "ohos.permission.CAMERA"; -privacyManager.stopUsingPermission(tokenID, permissionName).then(data => { - console.log(`promise: data->${JSON.stringify(data)}`); -}).catch(err => { - console.log(`Error: err->${JSON.stringify(err)}`); -}); +async stopUsingPermission() { + let bundleName = "com.ohos.permissionmanager"; // change to your bundle name + let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function + + let tokenID = appInfo.accessTokenId; + let permissionName = "ohos.permission.CAMERA"; + privacyManager.stopUsingPermission(tokenID, permissionName).then(data => { + console.log(`promise: data->${JSON.stringify(data)}`); + }).catch(err => { + console.log(`Error: err->${JSON.stringify(err)}`); + }); +} ``` ## privacyManager.stopUsingPermission9+ @@ -309,18 +319,20 @@ stopUsingPermission(tokenID: number, permissionName: string, callback: AsyncCall import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -let bundleName = "com.ohos.permissionmanager"; // change to your bundle name -let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - -let tokenID = appInfo.accessTokenId; -let permissionName = "ohos.permission.CAMERA"; -privacyManager.privacyManager.stopUsingPermission(tokenID, permissionName, (err, data)=> { - if (err) { - console.log(`Error: err->${JSON.stringify(err)}`); - } else { - console.log(`promise: data->${JSON.stringify(data)}`); - } -}); +async stopUsingPermission() { + let bundleName = "com.ohos.permissionmanager"; // change to your bundle name + let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function + + let tokenID = appInfo.accessTokenId; + let permissionName = "ohos.permission.CAMERA"; + privacyManager.privacyManager.stopUsingPermission(tokenID, permissionName, (err, data)=> { + if (err) { + console.log(`Error: err->${JSON.stringify(err)}`); + } else { + console.log(`promise: data->${JSON.stringify(data)}`); + } + }); +} ``` ## privacyManager.on9+ @@ -352,7 +364,7 @@ function OnPermissionUseStateChanged(data){ console.debug("receive permission state change, data:" + JSON.stringify(data)); } let type: 'activeStateChange' = 'activeStateChange'; -let permissionNameList: Array<string> = []; +let permissionNameList: Array = []; try{ privacyManager.on(type, permissionNameList, OnPermissionUseStateChanged); } @@ -387,7 +399,7 @@ off(type: 'activeStateChange', permissionNameList: Array<string>, callback import privacyManager from '@ohos.privacyManager'; let type: 'activeStateChange' = 'activeStateChange'; -let permissionNameList: Array<string> = []; +let permissionNameList: Array = []; try{ privacyManager.off(type, permissionNameList); } -- GitLab