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 140591d4593e3536c14eca6cf541ebf5359499c9..74df7ef2c393aedcbfff767a64fee10d05d7c07e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-privacyManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-privacyManager.md @@ -45,15 +45,14 @@ addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: n import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -async addPermissionUsedRecord() { - let bundleName = "com.ohos.permissionmanager"; // change to your bundle name - let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - +let bundleName = "com.ohos.permissionmanager"; // change to your bundle name +bundle.getApplicationInfo(bundleName, 16).then(appInfo => { 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 @@ -83,15 +82,14 @@ addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: n import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -async addPermissionUsedRecord() { - let bundleName = "com.ohos.permissionmanager"; // change to your bundle name - let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - +let bundleName = "com.ohos.permissionmanager"; // change to your bundle name +bundle.getApplicationInfo(bundleName, 16).then(appInfo => { 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 @@ -198,10 +196,8 @@ startUsingPermission(tokenID: number, permissionName: string): Promise<number import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -async startUsingPermission() { - let bundleName = "com.ohos.permissionmanager"; // change to your bundle name - let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - +let bundleName = "com.ohos.permissionmanager"; // change to your bundle name +bundle.getApplicationInfo(bundleName, 16).then(appInfo => { let tokenID = appInfo.accessTokenId; let permissionName = "ohos.permission.CAMERA"; privacyManager.startUsingPermission(tokenID, permissionName).then(data => { @@ -209,7 +205,8 @@ async startUsingPermission() { }).catch(err => { console.log(`Error: err->${JSON.stringify(err)}`); }); -} +}) + ``` ## privacyManager.startUsingPermission9+ @@ -236,20 +233,19 @@ startUsingPermission(tokenID: number, permissionName: string, callback: AsyncCal import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -async startUsingPermission() { - let bundleName = "com.ohos.permissionmanager"; // change to your bundle name - let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - +let bundleName = "com.ohos.permissionmanager"; // change to your bundle name +bundle.getApplicationInfo(bundleName, 16).then(appInfo => { 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 { + } else {S console.log(`promise: data->${JSON.stringify(data)}`); } }); -} +}) + ``` ## privacyManager.stopUsingPermission9+ @@ -281,10 +277,8 @@ stopUsingPermission(tokenID: number, permissionName: string): Promise<number& import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -async stopUsingPermission() { - let bundleName = "com.ohos.permissionmanager"; // change to your bundle name - let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - +let bundleName = "com.ohos.permissionmanager"; // change to your bundle name +bundle.getApplicationInfo(bundleName, 16).then(appInfo => { let tokenID = appInfo.accessTokenId; let permissionName = "ohos.permission.CAMERA"; privacyManager.stopUsingPermission(tokenID, permissionName).then(data => { @@ -292,7 +286,8 @@ async stopUsingPermission() { }).catch(err => { console.log(`Error: err->${JSON.stringify(err)}`); }); -} +}) + ``` ## privacyManager.stopUsingPermission9+ @@ -319,20 +314,19 @@ stopUsingPermission(tokenID: number, permissionName: string, callback: AsyncCall import bundle from '@ohos.bundle'; import privacyManager from '@ohos.privacyManager'; -async stopUsingPermission() { - let bundleName = "com.ohos.permissionmanager"; // change to your bundle name - let appInfo = await bundle.getApplicationInfo(bundleName, 16); // need async type function - +let bundleName = "com.ohos.permissionmanager"; // change to your bundle name +bundle.getApplicationInfo(bundleName, 16).then(appInfo => { let tokenID = appInfo.accessTokenId; let permissionName = "ohos.permission.CAMERA"; - privacyManager.privacyManager.stopUsingPermission(tokenID, permissionName, (err, data)=> { + 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+