From c87b5eb8285a107290b66ca9fb89753b6662da9d Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Tue, 28 Dec 2021 17:02:56 +0000 Subject: [PATCH 1/3] Add js-apis-account.md Signed-off-by: zhaoyuan17 --- .../reference/apis/js-apis-account.md | 3 +- .../reference/apis/js-apis-appAccount.md | 875 ++++++++++++++++++ 2 files changed, 877 insertions(+), 1 deletion(-) create mode 100644 zh-cn/application-dev/reference/apis/js-apis-appAccount.md diff --git a/zh-cn/application-dev/reference/apis/js-apis-account.md b/zh-cn/application-dev/reference/apis/js-apis-account.md index 1bec1b4c3aa..1727b66576b 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-account.md +++ b/zh-cn/application-dev/reference/apis/js-apis-account.md @@ -2,4 +2,5 @@ -- **[分布式帐号管理](js-apis-distributed-account.md)** \ No newline at end of file +- **[分布式帐号管理](js-apis-distributed-account.md)** +- **[应用帐号管理](js-apis-appAccount.md)** \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-appAccount.md b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md new file mode 100644 index 00000000000..b1829017a23 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md @@ -0,0 +1,875 @@ +# 应用帐号管理 + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** +> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + + +## 导入模块 + +``` +import account_appAccount from '@ohos.account.appAccount'; +``` + + +## account_appAccount.createAppAccountManager + +createAppAccountManager(): AppAccountManager; + +应用帐号管理:获取应用帐号模块对象。 + +- 返回值: + | 类型 | 说明 | + | -------- | -------- | + | AppAccountManager | 获取应用帐号模块的实例。 | + +- 示例: + ``` + var appAccountManager = account.createAppAccountManager(); + ``` + +## AppAccountManager + +管理应用帐号模块的实例。 + +### addAccount + +addAccount(name: string, callback: AsyncCallback<void>): void; + +将此应用的帐号名添加到帐号管理服务中,使用callback回调异步返回结果。 + +需要权限:无。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------- | ---- | ------------------------------------------ | + | name | string | 是 | 要添加的应用帐户的名称。 | + | callback | AsyncCallback<void> | 是 | 将此应用的帐号名添加到帐号管理服务的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.addAccount("WangWu", (err) => { + console.log("addAccount err: " + JSON.stringify(err)); + }); + ``` + +### addAccount + +addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void + +将此应用程序的帐号名和额外信息添加到帐号管理服务中,使用callback回调异步返回结果。 + +需要权限:无。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | --------- | ------------------- | ---- | ------------------------------------------------------------ | + | name | string | 是 | 要添加的应用帐户的名称。 | + | extraInfo | string | 是 | 要添加的应用帐户的额外信息(例如token等),额外的信息不能是应用帐号的敏感信息。 | + | callback | AsyncCallback<void> | 是 | 将此应用程序的帐号名和额外信息添加到帐号管理服务中的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.addAccount("LiSi", "token101", (err) => { + console.log("addAccount err: " + JSON.stringify(err)); + }); + ``` + + + +### addAccount + +addAccount(name: string, extraInfo?: string): Promise<void> + +将此应用的帐号名或额外信息添加到帐号管理服务中,使用Promise方式异步返回结果。 + +需要权限:无。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | --------- | ------ | ---- | ------------------------------------------------------------ | + | name | string | 是 | 要添加的应用帐户的名称。 | + | extraInfo | string | 是 | 要添加的应用帐户的额外信息,额外的信息不能是应用帐号的敏感信息。 | + +- 返回值: + + | 类型 | 说明 | + | ------------- | ---------------------------------- | + | Promise<void> | romise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.addAccount("LiSi", "token101").then(()=> { + console.log('addAccount Success'); + }).catch((err) => { + console.log("addAccount err: " + JSON.stringify(err)); + }); + ``` + +### deleteAccount + +deleteAccount(name: string, callback: AsyncCallback<void>): void + +从帐号管理服务中删除应用帐号,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------- | ---- | ---------------------------------- | + | name | string | 是 | 要删除的应用帐户的名称。 | + | callback | AsyncCallback<void> | 是 | 帐号管理服务中删除应用帐号的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.deleteAccount("ZhaoLiu", (err) => { + console.log("deleteAccount err: " + JSON.stringify(err)); + }); + ``` + +### deleteAccount + +deleteAccount(name: string): Promise<void> + +从帐号管理服务中删除应用帐号,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ------ | ------ | ---- | ------------------------ | + | name | string | 是 | 要删除的应用帐户的名称。 | + +- 返回值: + + | 类型 | 说明 | + | :------------ | :---------------------------------- | + | Promise<void> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.deleteAccount("ZhaoLiu").then(() => { + console.log('deleteAccount Success'); + }).catch((err) => { + console.log("deleteAccount err: " + JSON.stringify(err)); + }); + ``` + +### disableAppAccess + +disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void + +禁止指定第三方应用帐户的名称访问指定包名称的第三方应用,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ---------- | ------------------- | ---- | ------------------------------------------------------------ | + | name | string | 是 | 要禁用访问的第三方应用帐户的名称。 | + | bundleName | string | 是 | 第三方应用的包名。 | + | callback | AsyncCallback<void> | 是 | 禁止指定第三方应用帐户的名称访问指定包名称的第三方应用的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.disableAppAccess("ZhangSan", "com.huawei.ohos.accountjsdemo", (err) => { + console.log("disableAppAccess err: " + JSON.stringify(err)); + }); + ``` + +### disableAppAccess + +disableAppAccess(name: string, bundleName: string): Promise<void> + +禁止指定第三方应用帐户的名称访问指定包名称的第三方应用,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ---------- | ------ | ---- | ---------------------------------- | + | name | string | 是 | 要禁用访问的第三方应用帐户的名称。 | + | bundleName | string | 是 | 第三方应用的包名。 | + +- 返回值: + + | 类型 | 说明 | + | :------------ | :---------------------------------- | + | Promise<void> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.disableAppAccess("ZhangSan", "com.huawei.ohos.accountjsdemo").then(() => { + console.log('disableAppAccess Success'); + }).catch((err) => { + console.log("disableAppAccess err: " + JSON.stringify(err)); + }); + ``` + +### enableAppAccess + +enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void + +允许指定第三方应用帐户的名称访问指定包名称的第三方应用,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ---------- | ------------------- | ---- | ------------------------------------------------------------ | + | name | string | 是 | 应用帐号名称。 | + | bundleName | string | 是 | 第三方应用的包名。 | + | callback | AsyncCallback<void> | 是 | 允许指定第三方应用帐户的名称访问指定包名称的第三方应用的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.enableAppAccess("ZhangSan", "com.huawei.ohos.accountjsdemo", (err) => { + console.log("enableAppAccess: " + JSON.stringify(err)); + }); + ``` + +### enableAppAccess + +enableAppAccess(name: string, bundleName: string): Promise<void> + +允许指定第三方应用帐户的名称访问指定包名称的第三方应用,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ---------- | ------ | ---- | ------------------ | + | name | string | 是 | 应用帐号名称。 | + | bundleName | string | 是 | 第三方应用的包名。 | + +- 返回值: + + | 类型 | 说明 | + | :------------ | :---------------------------------- | + | Promise<void> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + app_account_instance.enableAppAccess("ZhangSan", "com.huawei.ohos.accountjsdemo").then(() => { + console.log('enableAppAccess Success'); + }).catch((err) => { + console.log("enableAppAccess err: " + JSON.stringify(err)); + }); + ``` + +### checkAppAccountSyncEnable + +checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void + +检查指定应用帐号是否允许应用数据同步,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ---------------------- | ---- | -------------------------------------------- | + | name | string | 是 | 应用帐号名称。 | + | callback | AsyncCallback<boolean> | 是 | 检查指定应用帐号是否允许应用数据同步的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => { + console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); + console.log('checkAppAccountSyncEnable result: ' + result); + }); + ``` + +### checkAppAccountSyncEnable + +checkAppAccountSyncEnable(name: string): Promise<boolean> + +检查指定应用帐号是否允许应用数据同步,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ------ | ------ | ---- | -------------- | + | name | string | 是 | 应用帐号名称。 | + +- 返回值: + + | 类型 | 说明 | + | :--------------- | :---------------------------------- | + | Promise<boolean> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => { + console.log('checkAppAccountSyncEnable, result: ' + data); + }).catch((err) => { + console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); + }); + ``` + +### setAccountCredential + +setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void + +设置此应用程序帐号的凭据,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------------- | ------------------- | ---- | ---------------------------- | + | name | string | 是 | 应用程序帐户的名称。 | + | credentialType | string | 是 | 要设置的凭据的类型。 | + | credential | string | 是 | 要设置的凭据。 | + | callback | AsyncCallback<void> | 是 | 设置此应用帐号的凭据的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => { + console.log("setAccountCredential err: " + JSON.stringify(err)); + }); + ``` + +### setAccountCredential + +setAccountCredential(name: string, credentialType: string, credential: string): Promise<void> + +设置此应用程序帐号的凭据,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------------- | ------ | ---- | -------------------- | + | name | string | 是 | 应用帐户的名称。 | + | credentialType | string | 是 | 要设置的凭据的类型。 | + | credential | string | 是 | 要设置的凭据。 | + +- 返回值: + + | 类型 | 说明 | + | :------------ | :---------------------------------- | + | Promise<void> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => { + console.log('setAccountCredential Success'); + }).catch((err) => { + console.log("setAccountCredential err: " + JSON.stringify(err)); + }); + ``` + +### setAccountExtraInfo + +setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void + +设置此应用程序帐号的额外信息,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | --------- | ------------------- | ---- | -------------------------------- | + | name | string | 是 | 应用帐户的名称。 | + | extraInfo | string | 是 | 要设置的额外信息。 | + | callback | AsyncCallback<void> | 是 | 设置此应用帐号的额外信息的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => { + console.log("setAccountExtraInfo err: " + JSON.stringify(err)); + }); + ``` + +### setAccountExtraInfo + +setAccountExtraInfo(name: string, extraInfo: string): Promise<void> + +设置此应用程序帐号的额外信息,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | --------- | ------ | ---- | ------------------ | + | name | string | 是 | 应用帐户的名称。 | + | extraInfo | string | 是 | 要设置的额外信息。 | + +- 返回值: + + | 类型 | 说明 | + | :------------ | :---------------------------------- | + | Promise<void> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => { + console.log('setAccountExtraInfo Success'); + }).catch((err) => { + console.log("setAccountExtraInfo err: " + JSON.stringify(err)); + }); + ``` + +### setAppAccountSyncEnable + +setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void + +设置指定的应用程序帐号是否允许应用程序数据同步,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------- | ---- | -------------------------------------------------- | + | name | string | 是 | 应用帐户的名称。 | + | isEnable | boolean | 是 | 是否允许应用数据同步。 | + | callback | AsyncCallback<void> | 是 | 设置指定的应用帐号是否允许应用程序数据同步的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => { + console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); + }); + ``` + +### setAppAccountSyncEnable + +setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void> + +设置指定的应用程序帐号是否允许应用程序数据同步,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------- | ---- | ---------------------- | + | name | string | 是 | 应用帐户的名称。 | + | isEnable | boolean | 是 | 是否允许应用数据同步。 | + +- 返回值: + + | 类型 | 说明 | + | :------------ | :---------------------------------- | + | Promise<void> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => { + console.log('setAppAccountSyncEnable Success'); + }).catch((err) => { + console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); + }); + ``` + +### setAssociatedData + +setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void + +设置与此应用程序帐号关联的数据,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------- | ---- | ---------------------------------- | + | name | string | 是 | 应用帐户的名称。 | + | key | string | 是 | 要设置的数据的键,密钥可以自定义。 | + | value | string | 是 | 要设置的数据的值。 | + | callback | AsyncCallback<void> | 是 | 设置与此应用帐号关联的数据的回调。 | + +- 示例: + + ``` + app_account_instance.setAssociatedData("ZhangSan", "k001", "v001", (err) => { + console.log("setAssociatedData err: " + JSON.stringify(err)); + }); + ``` + +### setAssociatedData + +setAssociatedData(name: string, key: string, value: string): Promise<void> + +设置与此应用程序帐号关联的数据,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ------ | ------ | ---- | ---------------------------------- | + | name | string | 是 | 应用帐户的名称。 | + | key | string | 是 | 要设置的数据的键,密钥可以自定义。 | + | value | string | 是 | 要设置的数据的值。 | + +- 返回值: + + | 类型 | 说明 | + | :------------ | :---------------------------------- | + | Promise<void> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => { + console.log('setAssociatedData Success'); + }).catch((err) => { + console.log("setAssociatedData err: " + JSON.stringify(err)); + }); + ``` + +### getAccountCredential + +getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void + +获取此应用帐号的凭据,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------------- | --------------------- | ---- | ---------------------------- | + | name | string | 是 | 应用帐号名称。 | + | credentialType | string | 是 | 要获取的凭据的类型。 | + | callback | AsyncCallback<string> | 是 | 获取此应用帐号的凭据的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => { + console.log("getAccountCredential err: " + JSON.stringify(err)); + console.log('getAccountCredential result: ' + result); + }); + ``` + +### getAccountCredential + +getAccountCredential(name: string, credentialType: string): Promise<string> + +获取此应用程序帐号的凭据,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------------- | ------ | ---- | -------------------- | + | name | string | 是 | 应用帐号名称。 | + | credentialType | string | 是 | 要获取的凭据的类型。 | + +- 返回值: + + | 类型 | 说明 | + | :-------------- | :---------------------------------- | + | Promise<string> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => { + console.log('getAccountCredential, result: ' + data); + }).catch((err) => { + console.log("getAccountCredential err: " + JSON.stringify(err)); + }); + ``` + +### getAccountExtraInfo + +getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void + +获取此应用帐号的额外信息,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | --------------------- | ---- | -------------------------------- | + | name | string | 是 | 应用帐号名称。 | + | callback | AsyncCallback<string> | 是 | 获取此应用帐号的额外信息的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => { + console.log("getAccountExtraInfo err: " + JSON.stringify(err)); + console.log('getAccountExtraInfo result: ' + result); + }); + ``` + +### getAccountExtraInfo + +getAccountExtraInfo(name: string): Promise<string> + +获取此应用程序帐号的额外信息,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ------ | ------ | ---- | -------------- | + | name | string | 是 | 应用帐号名称。 | + +- 返回值: + + | 类型 | 说明 | + | :-------------- | :---------------------------------- | + | Promise<string> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => { + console.log('getAccountExtraInfo, result: ' + data); + }).catch((err) => { + console.log("getAccountExtraInfo err: " + JSON.stringify(err)); + }); + ``` + +### getAssociatedData + +getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void + +获取与此应用程序帐号关联的数据,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | --------------------- | ---- | ---------------------------------- | + | name | string | 是 | 应用帐号名称。 | + | key | string | 是 | 要获取的数据的key。 | + | callback | AsyncCallback<string> | 是 | 获取与此应用帐号关联的数据的回调。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => { + console.log("getAssociatedData err: " + JSON.stringify(err)); + console.log('getAssociatedData result: ' + result); + }); + ``` + +### getAssociatedData + +getAssociatedData(name: string, key: string): Promise<string> + +获取与此应用程序帐号关联的数据,使用Promise方式异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ------ | ------ | ---- | ------------------- | + | name | string | 是 | 应用帐号名称。 | + | key | string | 是 | 要获取的数据的key。 | + +- 返回值: + + | 类型 | 说明 | + | :-------------- | :---------------------------------- | + | Promise<string> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => { + console.log('getAssociatedData: ' + data); + }).catch((err) => { + console.log("getAssociatedData err: " + JSON.stringify(err)); + }); + ``` + +### getAllAccessibleAccounts + +getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void; + +获取全部应用已授权帐号信息。 + +需要权限:ohos.permission.GET_ACCOUNTS_PRIVILEGED,系统应用可用。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------------------ | ---- | ---------------- | + | callback | AsyncCallback<Array<AppAccountInfo>> | 是 | 应用帐号信息列表 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAllAccessibleAccounts((err, data)=>{ + console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err)); + console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data)); + }); + ``` + +### getAllAccessibleAccounts + +getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>>; + +获取全部应用已授权帐号信息。 + +需要权限:ohos.permission.GET_ACCOUNTS_PRIVILEGED,系统应用可用。 + +- 参数: + + | 类型 | 说明 | + | ------------------------------ | ----------------------------------- | + | Promise<Array<AppAccountInfo>> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAllAccessibleAccounts().then((data) => { + console.log('getAllAccessibleAccounts: ' + data); + }).catch((err) => { + console.log("getAllAccessibleAccounts err: " + JSON.stringify(err)); + }); + ``` + +### getAllAccounts + +getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void; + +获取指定应用全部帐号信息。 + +需要权限:ohos.permission.GET_ACCOUNTS_PRIVILEGED,系统应用可用。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------------------ | ---- | ---------------- | + | owner | string | 是 | 应用包名称 | + | callback | AsyncCallback<Array<AppAccountInfo>> | 是 | 应用帐号信息列表 | + +- 示例: + + ``` + const appAccountManager = account.createAppAccountManager(); + const selfBundle = "com.example.actsgetallaaccounts"; + appAccountManager.getAllAccounts(selfBundle, (err, data)=>{ + console.debug("getAllAccounts err:" + JSON.stringify(err)); + console.debug("getAllAccounts data:" + JSON.stringify(data)); + }); + ``` + +### getAllAccounts + +getAllAccounts(owner: string): Promise<Array<AppAccountInfo>>; + +获取指定应用全部帐号信息。 + +需要权限:ohos.permission.GET_ACCOUNTS_PRIVILEGED,系统应用可用。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | ------ | ------ | ---- | ---------- | + | owner | string | 是 | 应用包名称 | + +- 参数: + + | 类型 | 说明 | + | ------------------------------ | ----------------------------------- | + | Promise<Array<AppAccountInfo>> | Promise实例,用于获取异步返回结果。 | + +- 示例: + + ``` + const appAccountManager = account_appAccount.createAppAccountManager(); + const selfBundle = "com.example.actsgetallaaccounts"; + appAccountManager.getAllAccounts(selfBundle).then((data) => { + console.log('getAllAccounts: ' + data); + }).catch((err) => { + console.log("getAllAccounts err: " + JSON.stringify(err)); + }); + ``` + +### on('change') + +on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void; + +订阅指定帐号所有者的帐户变更事件,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | + | type | 'change' | 是 | 关于帐户更改事件,当帐户所有者更新帐户时,订阅者将收到通知。 | + | owners | Array<string> | 是 | 指示帐户的所有者。 | + | callback | Callback<Array<AppAccountInfo>> | 是 | 订阅指定帐号所有者的帐户变更事件的回调。 | + +- 示例: + + ``` + const appAccountManager = account.createAppAccountManager(); + function changeOnCallback(data){ + console.debug("receive change data:" + JSON.stringify(data)); + } + try{ + appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); + } + catch(err){ + console.error("on accountOnOffDemo err:" + JSON.stringify(err)); + } + ``` + +### off('change') + +off(type: 'change', callback?: Callback<void>): void; + +取消订阅帐号事件,使用callback回调异步返回结果。 + +- 参数: + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------------------- | ---- | ------------------------ | + | type | 'change' | 是 | 关于帐户更改事件。 | + | callback | Callback<void> | 否 | 取消订阅帐号事件的回调。 | + +- 示例: + + ``` + const appAccountManager = account.createAppAccountManager(); + function changeOnCallback(data){ + console.debug("receive change data:" + JSON.stringify(data)); + appAccountManager.off('change', function(){ + console.debug("off finish"); + } + } + try{ + appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); + } + catch(err){ + console.error("on accountOnOffDemo err:" + JSON.stringify(err)); + } + ``` + +## AppAccountInfo + + + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------------ | +| owner | string | 是 | 所有者是应用帐户。 | +| name | string | 是 | 应用帐户的名称。 | + -- Gitee From 745336959e4cc361e1384f86131b913987ade11b Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Tue, 28 Dec 2021 17:22:06 +0000 Subject: [PATCH 2/3] Update js-apis-appAccount.md Signed-off-by: zhaoyuan17 --- .../reference/apis/js-apis-appAccount.md | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-appAccount.md b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md index b1829017a23..b2f2eb3b594 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-appAccount.md +++ b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md @@ -57,7 +57,7 @@ addAccount(name: string, callback: AsyncCallback<void>): void; ### addAccount -addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void +addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void; 将此应用程序的帐号名和额外信息添加到帐号管理服务中,使用callback回调异步返回结果。 @@ -84,7 +84,7 @@ addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>) ### addAccount -addAccount(name: string, extraInfo?: string): Promise<void> +addAccount(name: string, extraInfo?: string): Promise<void>; 将此应用的帐号名或额外信息添加到帐号管理服务中,使用Promise方式异步返回结果。 @@ -116,7 +116,7 @@ addAccount(name: string, extraInfo?: string): Promise<void> ### deleteAccount -deleteAccount(name: string, callback: AsyncCallback<void>): void +deleteAccount(name: string, callback: AsyncCallback<void>): void; 从帐号管理服务中删除应用帐号,使用callback回调异步返回结果。 @@ -138,7 +138,7 @@ deleteAccount(name: string, callback: AsyncCallback<void>): void ### deleteAccount -deleteAccount(name: string): Promise<void> +deleteAccount(name: string): Promise<void>; 从帐号管理服务中删除应用帐号,使用Promise方式异步返回结果。 @@ -167,7 +167,7 @@ deleteAccount(name: string): Promise<void> ### disableAppAccess -disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void +disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void; 禁止指定第三方应用帐户的名称访问指定包名称的第三方应用,使用callback回调异步返回结果。 @@ -190,7 +190,7 @@ disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<vo ### disableAppAccess -disableAppAccess(name: string, bundleName: string): Promise<void> +disableAppAccess(name: string, bundleName: string): Promise<void>; 禁止指定第三方应用帐户的名称访问指定包名称的第三方应用,使用Promise方式异步返回结果。 @@ -220,7 +220,7 @@ disableAppAccess(name: string, bundleName: string): Promise<void> ### enableAppAccess -enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void +enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void; 允许指定第三方应用帐户的名称访问指定包名称的第三方应用,使用callback回调异步返回结果。 @@ -243,7 +243,7 @@ enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<voi ### enableAppAccess -enableAppAccess(name: string, bundleName: string): Promise<void> +enableAppAccess(name: string, bundleName: string): Promise<void>; 允许指定第三方应用帐户的名称访问指定包名称的第三方应用,使用Promise方式异步返回结果。 @@ -272,7 +272,7 @@ enableAppAccess(name: string, bundleName: string): Promise<void> ### checkAppAccountSyncEnable -checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void +checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void; 检查指定应用帐号是否允许应用数据同步,使用callback回调异步返回结果。 @@ -295,7 +295,7 @@ checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): ### checkAppAccountSyncEnable -checkAppAccountSyncEnable(name: string): Promise<boolean> +checkAppAccountSyncEnable(name: string): Promise<boolean>; 检查指定应用帐号是否允许应用数据同步,使用Promise方式异步返回结果。 @@ -324,7 +324,7 @@ checkAppAccountSyncEnable(name: string): Promise<boolean> ### setAccountCredential -setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void +setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void; 设置此应用程序帐号的凭据,使用callback回调异步返回结果。 @@ -348,7 +348,7 @@ setAccountCredential(name: string, credentialType: string, credential: string,ca ### setAccountCredential -setAccountCredential(name: string, credentialType: string, credential: string): Promise<void> +setAccountCredential(name: string, credentialType: string, credential: string): Promise<void>; 设置此应用程序帐号的凭据,使用Promise方式异步返回结果。 @@ -379,7 +379,7 @@ setAccountCredential(name: string, credentialType: string, credential: string): ### setAccountExtraInfo -setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void +setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void; 设置此应用程序帐号的额外信息,使用callback回调异步返回结果。 @@ -402,7 +402,7 @@ setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback< ### setAccountExtraInfo -setAccountExtraInfo(name: string, extraInfo: string): Promise<void> +setAccountExtraInfo(name: string, extraInfo: string): Promise<void>; 设置此应用程序帐号的额外信息,使用Promise方式异步返回结果。 @@ -432,7 +432,7 @@ setAccountExtraInfo(name: string, extraInfo: string): Promise<void> ### setAppAccountSyncEnable -setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void +setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void; 设置指定的应用程序帐号是否允许应用程序数据同步,使用callback回调异步返回结果。 @@ -455,7 +455,7 @@ setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback ### setAppAccountSyncEnable -setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void> +setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void>; 设置指定的应用程序帐号是否允许应用程序数据同步,使用Promise方式异步返回结果。 @@ -485,7 +485,7 @@ setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void> ### setAssociatedData -setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void +setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void; 设置与此应用程序帐号关联的数据,使用callback回调异步返回结果。 @@ -508,7 +508,7 @@ setAssociatedData(name: string, key: string, value: string, callback: AsyncCallb ### setAssociatedData -setAssociatedData(name: string, key: string, value: string): Promise<void> +setAssociatedData(name: string, key: string, value: string): Promise<void>; 设置与此应用程序帐号关联的数据,使用Promise方式异步返回结果。 @@ -539,7 +539,7 @@ setAssociatedData(name: string, key: string, value: string): Promise<void> ### getAccountCredential -getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void +getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void; 获取此应用帐号的凭据,使用callback回调异步返回结果。 @@ -563,7 +563,7 @@ getAccountCredential(name: string, credentialType: string, callback: AsyncCallba ### getAccountCredential -getAccountCredential(name: string, credentialType: string): Promise<string> +getAccountCredential(name: string, credentialType: string): Promise<string>; 获取此应用程序帐号的凭据,使用Promise方式异步返回结果。 @@ -593,7 +593,7 @@ getAccountCredential(name: string, credentialType: string): Promise<string> ### getAccountExtraInfo -getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void +getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void; 获取此应用帐号的额外信息,使用callback回调异步返回结果。 @@ -616,7 +616,7 @@ getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void ### getAccountExtraInfo -getAccountExtraInfo(name: string): Promise<string> +getAccountExtraInfo(name: string): Promise<string>; 获取此应用程序帐号的额外信息,使用Promise方式异步返回结果。 @@ -645,7 +645,7 @@ getAccountExtraInfo(name: string): Promise<string> ### getAssociatedData -getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void +getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void; 获取与此应用程序帐号关联的数据,使用callback回调异步返回结果。 @@ -669,7 +669,7 @@ getAssociatedData(name: string, key: string, callback: AsyncCallback<string&g ### getAssociatedData -getAssociatedData(name: string, key: string): Promise<string> +getAssociatedData(name: string, key: string): Promise<string>; 获取与此应用程序帐号关联的数据,使用Promise方式异步返回结果。 -- Gitee From becb6044557c0b9b6a96400b48ea37fae8e72f34 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Tue, 28 Dec 2021 17:40:39 +0000 Subject: [PATCH 3/3] Add permission for api content Signed-off-by: zhaoyuan17 --- .../application-dev/reference/apis/js-apis-appAccount.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zh-cn/application-dev/reference/apis/js-apis-appAccount.md b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md index b2f2eb3b594..149be32739d 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-appAccount.md +++ b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md @@ -276,6 +276,8 @@ checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): 检查指定应用帐号是否允许应用数据同步,使用callback回调异步返回结果。 +需要权限:ohos.permission.DISTRIBUTED_DATASYNC,系统应用可用。 + - 参数: | 参数名 | 类型 | 必填 | 说明 | @@ -299,6 +301,8 @@ checkAppAccountSyncEnable(name: string): Promise<boolean>; 检查指定应用帐号是否允许应用数据同步,使用Promise方式异步返回结果。 +需要权限:ohos.permission.DISTRIBUTED_DATASYNC,系统应用可用。 + - 参数: | 参数名 | 类型 | 必填 | 说明 | @@ -436,6 +440,8 @@ setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback 设置指定的应用程序帐号是否允许应用程序数据同步,使用callback回调异步返回结果。 +需要权限:ohos.permission.DISTRIBUTED_DATASYNC,系统应用可用。 + - 参数: | 参数名 | 类型 | 必填 | 说明 | @@ -459,6 +465,8 @@ setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void>; 设置指定的应用程序帐号是否允许应用程序数据同步,使用Promise方式异步返回结果。 +需要权限:ohos.permission.DISTRIBUTED_DATASYNC,系统应用可用。 + - 参数: | 参数名 | 类型 | 必填 | 说明 | -- Gitee