@ohos.account.osAccount (系统帐号管理)

本模块提供管理系统帐号的基础能力,包括系统帐号的添加、删除、查询、设置、订阅、启动等功能。

说明:

本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import account_osAccount from '@ohos.account.osAccount';

account_osAccount.getAccountManager

getAccountManager(): AccountManager

获取系统帐号管理对象。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
AccountManager 系统帐号管理对象。

示例:

let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();

OsAccountType

表示系统帐号类型的枚举。

系统能力: SystemCapability.Account.OsAccount。

名称 说明
ADMIN 0 管理员帐号。
NORMAL 1 普通帐号。
GUEST 2 访客帐号。

AccountManager

系统帐号管理类。

checkMultiOsAccountEnabled9+

checkMultiOsAccountEnabled(callback: AsyncCallback<boolean>): void

判断是否支持多系统帐号。使用callback异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<boolean> 回调函数。返回true表示支持多系统帐号;返回false表示不支持。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.checkMultiOsAccountEnabled((err: BusinessError, isEnabled: boolean) => {
    if (err) {
      console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
    } else {
    console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
    }
  });
} catch (err) {
  console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err));
}

checkMultiOsAccountEnabled9+

checkMultiOsAccountEnabled(): Promise<boolean>

判断是否支持多系统帐号。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示支持多系统帐号;返回false表示不支持。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
try {
  let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
  accountManager.checkMultiOsAccountEnabled().then((isEnabled: boolean) => {
    console.log('checkMultiOsAccountEnabled successfully, isEnabled: ' + isEnabled);
  }).catch((err: BusinessError) => {
    console.error(`checkMultiOsAccountEnabled failed, code is ${err.code}, message is ${err.message}`);
  });
} catch (err) {
  console.log('checkMultiOsAccountEnabled failed, error:' + JSON.stringify(err));
}

checkOsAccountActivated(deprecated)

checkOsAccountActivated(localId: number, callback: AsyncCallback<boolean>): void

判断指定系统帐号是否处于激活状态。使用callback异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
callback AsyncCallback<boolean> 回调函数。返回true表示帐号已激活;返回false表示帐号未激活。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId.
12300003 Account not found.

示例: 判断ID为100的系统帐号是否处于激活状态

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.checkOsAccountActivated(localId, (err: BusinessError, isActivated: boolean) => {
    if (err) {
      console.log('checkOsAccountActivated failed, error:' + JSON.stringify(err));
    } else {
      console.log('checkOsAccountActivated successfully, isActivated:' + isActivated);
    }
  });
} catch (err) {
  console.log('checkOsAccountActivated exception: ' + JSON.stringify(err));
}

checkOsAccountActivated(deprecated)

checkOsAccountActivated(localId: number): Promise<boolean>

判断指定系统帐号是否处于激活状态。使用Promise异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示帐号已激活;返回false表示帐号未激活。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId.
12300003 Account not found.

示例: 判断ID为100的系统帐号是否处于激活状态

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.checkOsAccountActivated(localId).then((isActivated: boolean) => {
    console.log('checkOsAccountActivated successfully, isActivated: ' + isActivated);
  }).catch((err: BusinessError) => {
    console.log('checkOsAccountActivated failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('checkOsAccountActivated exception: ' + JSON.stringify(err));
}

isOsAccountConstraintEnabled11+

isOsAccountConstraintEnabled(constraint: string): Promise<boolean>

判断当前系统帐号是否使能指定约束。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
constraint string 指定的约束名称。

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例: 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let constraint: string = 'constraint.wifi';
try {
  accountManager.isOsAccountConstraintEnabled(constraint).then((isEnabled: boolean) => {
    console.log('isOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
  }).catch((err: BusinessError) => {
    console.log('isOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('isOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
}

checkOsAccountConstraintEnabled(deprecated)

checkOsAccountConstraintEnabled(localId: number, constraint: string, callback: AsyncCallback<boolean>): void

判断指定系统帐号是否具有指定约束。使用callback异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
constraint string 指定的约束名称。
callback AsyncCallback<boolean> 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId or constraint.
12300003 Account not found.

示例: 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
let constraint: string = 'constraint.wifi';
try {
  accountManager.checkOsAccountConstraintEnabled(localId, constraint, (err: BusinessError, isEnabled: boolean)=>{
    if (err) {
      console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
    } else {
      console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
    }
  });
} catch (err) {
  console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
}

checkOsAccountConstraintEnabled(deprecated)

checkOsAccountConstraintEnabled(localId: number, constraint: string): Promise<boolean>

判断指定系统帐号是否具有指定约束。使用Promise异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
constraint string 指定的约束名称。

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId or constraint.
12300003 Account not found.

示例: 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
let constraint: string = 'constraint.wifi';
try {
  accountManager.checkOsAccountConstraintEnabled(localId, constraint).then((isEnabled: boolean) => {
    console.log('checkOsAccountConstraintEnabled successfully, isEnabled: ' + isEnabled);
  }).catch((err: BusinessError) => {
    console.log('checkOsAccountConstraintEnabled failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('checkOsAccountConstraintEnabled exception: ' + JSON.stringify(err));
}

checkOsAccountTestable9+

checkOsAccountTestable(callback: AsyncCallback<boolean>): void

检查当前系统帐号是否为测试帐号。使用callback异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<boolean> 回调函数。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.checkOsAccountTestable((err: BusinessError, isTestable: boolean) => {
    if (err) {
      console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
    } else {
      console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
    }
  });
} catch (err) {
  console.log('checkOsAccountTestable error: ' + JSON.stringify(err));
}

checkOsAccountTestable9+

checkOsAccountTestable(): Promise<boolean>

检查当前系统帐号是否为测试帐号。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.checkOsAccountTestable().then((isTestable: boolean) => {
    console.log('checkOsAccountTestable successfully, isTestable: ' + isTestable);
  }).catch((err: BusinessError) => {
    console.log('checkOsAccountTestable failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('checkOsAccountTestable exception: ' + JSON.stringify(err));
}

isOsAccountUnlocked11+

isOsAccountUnlocked(): Promise<boolean>

检查当前系统帐号是否已认证解锁。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.isOsAccountUnlocked().then((isVerified: boolean) => {
    console.log('isOsAccountUnlocked successfully, isVerified: ' + isVerified);
  }).catch((err: BusinessError) => {
    console.log('isOsAccountUnlocked failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('isOsAccountUnlocked exception: ' + JSON.stringify(err));
}

checkOsAccountVerified(deprecated)

checkOsAccountVerified(callback: AsyncCallback<boolean>): void

检查当前系统帐号是否已认证解锁。使用callback异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。建议使用isOsAccountUnlocked替代。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<boolean> 回调函数。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.checkOsAccountVerified((err: BusinessError, isVerified: boolean) => {
    if (err) {
      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
    } else {
      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
    }
  });
} catch (err) {
  console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
}

checkOsAccountVerified(deprecated)

checkOsAccountVerified(): Promise<boolean>

检查当前系统帐号是否已认证解锁。使用Promise异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。建议使用isOsAccountUnlocked替代。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
    console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
  }).catch((err: BusinessError) => {
    console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
}

checkOsAccountVerified(deprecated)

checkOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void

检查指定系统帐号是否已验证。使用callback异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
callback AsyncCallback<boolean> 回调函数。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId.
12300003 Account not found.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.checkOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
    if (err) {
      console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
    } else {
      console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
    }
  });
} catch (err) {
  console.log('checkOsAccountVerified exception: ' + err);
}

checkOsAccountVerified(deprecated)

checkOsAccountVerified(localId: number): Promise<boolean>

检查指定系统帐号是否已验证。使用Promise异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。不填则检查当前系统帐号是否已验证。

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示当前帐号已认证解锁;返回false表示当前帐号未认证解锁。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId.
12300003 Account not found.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.checkOsAccountVerified(localId).then((isVerified: boolean) => {
    console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
  }).catch((err: BusinessError) => {
    console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
}

checkOsAccountVerified9+

checkOsAccountVerified(): Promise<boolean>

检查当前系统帐号是否已验证。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示当前帐号已验证;返回false表示当前帐号未验证。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.checkOsAccountVerified().then((isVerified: boolean) => {
    console.log('checkOsAccountVerified successfully, isVerified: ' + isVerified);
  }).catch((err: BusinessError) => {
    console.log('checkOsAccountVerified failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('checkOsAccountVerified exception: ' + JSON.stringify(err));
}

getOsAccountCount9+

getOsAccountCount(callback: AsyncCallback<number>): void

获取已创建的系统帐号数量。使用callback异步回调。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<number> 回调函数。当获取成功时,err为null,data为已创建的系统帐号的数量;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountCount((err: BusinessError, count: number) => {
    if (err) {
      console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
    } else {
      console.log('getOsAccountCount successfully, count: ' + count);
    }
  });
} catch (err) {
  console.log('getOsAccountCount exception: ' + JSON.stringify(err));
}

getOsAccountCount9+

getOsAccountCount(): Promise<number>

获取已创建的系统帐号数量。使用Promise异步回调。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<number> Promise对象,返回已创建的系统帐号的数量。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountCount().then((count: number) => {
    console.log('getOsAccountCount successfully, count: ' + count);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountCount failed, error: ' + JSON.stringify(err));
  });
} catch(err) {
  console.log('getOsAccountCount exception: ' + JSON.stringify(err));
}

getOsAccountLocalId9+

getOsAccountLocalId(callback: AsyncCallback<number>): void

获取当前进程所属的系统帐号ID,使用callback异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<number> 回调函数。当获取成功时,err为null,data为当前进程所属的系统帐号ID;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountLocalId((err: BusinessError, localId: number) => {
    if (err) {
      console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
    } else {
      console.log('getOsAccountLocalId successfully, localId: ' + localId);
    }
  });
} catch (err) {
  console.log('getOsAccountLocalId exception: ' + JSON.stringify(err));
}

getOsAccountLocalId9+

getOsAccountLocalId(): Promise<number>

获取当前进程所属的系统帐号ID,使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<number> Promise对象,返回当前进程所属的系统帐号ID。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountLocalId().then((localId: number) => {
    console.log('getOsAccountLocalId successfully, localId: ' + localId);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountLocalId failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('getOsAccountLocalId exception: ' + JSON.stringify(err));
}

getOsAccountLocalIdForUid9+

getOsAccountLocalIdForUid(uid: number, callback: AsyncCallback<number>): void

根据uid查询对应的系统帐号ID,使用callback异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
uid number 进程uid。
callback AsyncCallback<number> 回调函数。如果查询成功,err为null,data为对应的系统帐号ID;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid uid.

示例: 查询值为12345678的uid所属的系统帐号的帐号ID

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let uid: number = 12345678;
try {
  accountManager.getOsAccountLocalIdForUid(uid, (err: BusinessError, localId: number) => {
    if (err) {
      console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
    }
    console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
  });
} catch (err) {
  console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
}

getOsAccountLocalIdForUid9+

getOsAccountLocalIdForUid(uid: number): Promise<number>

根据uid查询对应的系统帐号ID,使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
uid number 进程uid。

返回值:

类型 说明
Promise<number> Promise对象,返回指定uid对应的系统帐号ID。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid uid.

示例: 查询值为12345678的uid所属的系统帐号ID

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let uid: number = 12345678;
try {
  accountManager.getOsAccountLocalIdForUid(uid).then((localId: number) => {
    console.log('getOsAccountLocalIdForUid successfully, localId: ' + localId);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountLocalIdForUid failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('getOsAccountLocalIdForUid exception: ' + JSON.stringify(err));
}

getOsAccountLocalIdForUidSync10+

getOsAccountLocalIdForUidSync(uid: number): number

根据uid查询对应的系统帐号ID。使用同步方式返回结果。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
uid number 进程uid。

返回值:

类型 说明
number 返回指定uid对应的系统帐号ID。

错误码:

错误码ID 错误信息
12300002 Invalid uid.

示例: 查询值为12345678的uid所属的系统帐号ID

let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let uid: number = 12345678;
try {
  let localId : number = accountManager.getOsAccountLocalIdForUidSync(uid);
  console.log('getOsAccountLocalIdForUidSync successfully, localId: ' + localId);
} catch (err) {
  console.log('getOsAccountLocalIdForUidSync exception: ' + JSON.stringify(err));
}

getOsAccountLocalIdForDomain9+

getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void

根据域帐号信息,获取与其关联的系统帐号ID。使用callback异步回调。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
domainInfo DomainAccountInfo 域帐号信息。
callback AsyncCallback<number> 回调函数。如果查询成功,err为null,data为域帐号关联的系统帐号ID;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid domainInfo.

示例:

import { BusinessError } from '@ohos.base';
let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountLocalIdForDomain(domainInfo, (err: BusinessError, localId: number) => {
    if (err) {
      console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
    } else {
      console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
    }
  });
} catch (err) {
  console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
}

getOsAccountLocalIdForDomain9+

getOsAccountLocalIdForDomain(domainInfo: DomainAccountInfo): Promise<number>

根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用Promise异步回调。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
domainInfo DomainAccountInfo 域帐号信息。

返回值:

类型 说明
Promise<number> Promise对象,返回域帐号关联的系统帐号ID。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid domainInfo.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
try {
  accountManager.getOsAccountLocalIdForDomain(domainInfo).then((localId: number) => {
    console.log('getOsAccountLocalIdForDomain successfully, localId: ' + localId);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountLocalIdForDomain failed, error: ' + JSON.stringify(err));
  });
} catch (err) {
  console.log('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err));
}

getOsAccountConstraints(deprecated)

getOsAccountConstraints(localId: number, callback: AsyncCallback<Array<string>>): void

获取指定系统帐号的全部约束。使用callback异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
callback AsyncCallback<Array<string>> 回调函数,如果获取成功,err为null,data为该系统帐号的全部约束;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId.
12300003 Account not found.

示例: 获取ID为100的系统帐号的全部约束

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.getOsAccountConstraints(localId, (err: BusinessError, constraints: string[]) => {
    if (err) {
      console.log('getOsAccountConstraints failed, err: ' + JSON.stringify(err));
    } else {
      console.log('getOsAccountConstraints successfully, constraints: ' + JSON.stringify(constraints));
    }
  });
} catch (err) {
  console.log('getOsAccountConstraints exception: ' + JSON.stringify(err));
}

getOsAccountConstraints(deprecated)

getOsAccountConstraints(localId: number): Promise<Array<string>>

获取指定系统帐号的全部约束。使用Promise异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。

返回值:

类型 说明
Promise<Array<string>> Promise对象,返回指定系统帐号的全部约束

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId.
12300003 Account not found.

示例: 获取ID为100的系统帐号的全部约束

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.getOsAccountConstraints(localId).then((constraints: string[]) => {
    console.log('getOsAccountConstraints, constraints: ' + constraints);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountConstraints err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('getOsAccountConstraints exception: ' + JSON.stringify(e));
}

getActivatedOsAccountLocalIds9+

getActivatedOsAccountLocalIds(callback: AsyncCallback<Array<number>>): void

查询当前处于激活状态的系统帐号的ID列表。使用callback异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<Array<number>> 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统帐号的ID列表;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getActivatedOsAccountLocalIds((err: BusinessError, idArray: number[])=>{
    console.log('getActivatedOsAccountLocalIds err:' + JSON.stringify(err));
    console.log('getActivatedOsAccountLocalIds idArray length:' + idArray.length);
    for(let i=0;i<idArray.length;i++) {
      console.info('activated os account id: ' + idArray[i]);
    }
  });
} catch (e) {
  console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
}

getActivatedOsAccountLocalIds9+

getActivatedOsAccountLocalIds(): Promise<Array<number>>

查询当前处于激活状态的系统帐号的ID列表。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<Array<number>> Promise对象,返回当前处于激活状态的系统帐号的ID列表。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getActivatedOsAccountLocalIds().then((idArray: number[]) => {
    console.log('getActivatedOsAccountLocalIds, idArray: ' + idArray);
  }).catch((err: BusinessError) => {
    console.log('getActivatedOsAccountLocalIds err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('getActivatedOsAccountLocalIds exception: ' + JSON.stringify(e));
}

getCurrentOsAccount(deprecated)

getCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void

查询当前进程所属的系统帐号的信息。使用callback异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS10+,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<OsAccountInfo> 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号信息;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{
    console.log('getCurrentOsAccount err:' + JSON.stringify(err));
    console.log('getCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
  });
} catch (e) {
  console.log('getCurrentOsAccount exception: ' + JSON.stringify(e));
}

getCurrentOsAccount(deprecated)

getCurrentOsAccount(): Promise<OsAccountInfo>

查询当前进程所属的系统帐号的信息。使用Promise异步回调。

说明:

从 API version 9开始支持,从API version 11开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.GET_LOCAL_ACCOUNTS10+,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<OsAccountInfo> Promise对象,返回当前进程所属的系统帐号信息。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => {
    console.log('getCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
  }).catch((err: BusinessError) => {
    console.log('getCurrentOsAccount err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('getCurrentOsAccount exception: ' + JSON.stringify(e));
}

getOsAccountType9+

getOsAccountType(callback: AsyncCallback<OsAccountType>): void

查询当前进程所属的系统帐号的帐号类型。使用callback异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<OsAccountType> 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号的帐号类型;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountType((err: BusinessError, accountType: account_osAccount.OsAccountType) => {
    console.log('getOsAccountType err: ' + JSON.stringify(err));
    console.log('getOsAccountType accountType: ' + accountType);
  });
} catch (e) {
  console.log('getOsAccountType exception: ' + JSON.stringify(e));
}

getOsAccountType9+

getOsAccountType(): Promise<OsAccountType>

查询当前进程所属的系统帐号的帐号类型。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<OsAccountType> Promise对象,返回当前进程所属的系统帐号的帐号类型。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.getOsAccountType().then((accountType: account_osAccount.OsAccountType) => {
    console.log('getOsAccountType, accountType: ' + accountType);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountType err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('getOsAccountType exception: ' + JSON.stringify(e));
}

queryDistributedVirtualDeviceId9+

queryDistributedVirtualDeviceId(callback: AsyncCallback<string>): void

获取分布式虚拟设备ID。使用callback异步回调。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS(仅系统应用可申请)或 ohos.permission.DISTRIBUTED_DATASYNC

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<string> 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.queryDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
    console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
    console.log('queryDistributedVirtualDeviceId virtualID: ' + virtualID);
  });
} catch (e) {
  console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
}

queryDistributedVirtualDeviceId9+

queryDistributedVirtualDeviceId(): Promise<string>

获取分布式虚拟设备ID。使用Promise异步回调。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS(仅系统应用可申请)或 ohos.permission.DISTRIBUTED_DATASYNC

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<string> Promise对象,返回分布式虚拟设备ID。

错误码:

错误码ID 错误信息
12300001 System service exception.

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
try {
  accountManager.queryDistributedVirtualDeviceId().then((virtualID: string) => {
    console.log('queryDistributedVirtualDeviceId, virtualID: ' + virtualID);
  }).catch((err: BusinessError) => {
    console.log('queryDistributedVirtualDeviceId err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('queryDistributedVirtualDeviceId exception: ' + JSON.stringify(e));
}

getOsAccountLocalIdForSerialNumber9+

getOsAccountLocalIdForSerialNumber(serialNumber: number, callback: AsyncCallback<number>): void

通过SN码查询与其关联的系统帐号的帐号ID。使用callback异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
serialNumber number 帐号SN码。
callback AsyncCallback<number> 回调函数。如果成功,err为null,data为与SN码关联的系统帐号的帐号ID;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid serialNumber.
12300003 The account indicated by serialNumber dose not exist.

示例: 查询与SN码12345关联的系统帐号的ID

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let serialNumber: number = 12345;
try {
  accountManager.getOsAccountLocalIdForSerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
    console.log('ger localId err:' + JSON.stringify(err));
    console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
  });
} catch (e) {
  console.log('ger localId exception: ' + JSON.stringify(e));
}

getOsAccountLocalIdForSerialNumber9+

getOsAccountLocalIdForSerialNumber(serialNumber: number): Promise<number>

通过SN码查询与其关联的系统帐号的帐号ID。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
serialNumber number 帐号SN码。

返回值:

类型 说明
Promise<number> Promise对象,返回与SN码关联的系统帐号的帐号ID。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid serialNumber.
12300003 The account indicated by serialNumber dose not exist.

示例: 查询与SN码12345关联的系统帐号的ID

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let serialNumber: number = 12345;
try {
  accountManager.getOsAccountLocalIdForSerialNumber(serialNumber).then((localId: number) => {
    console.log('getOsAccountLocalIdForSerialNumber localId: ' + localId);
  }).catch((err: BusinessError) => {
    console.log('getOsAccountLocalIdForSerialNumber err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('getOsAccountLocalIdForSerialNumber exception: ' + JSON.stringify(e));
}

getSerialNumberForOsAccountLocalId9+

getSerialNumberForOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void

通过系统帐号ID获取与该系统帐号关联的SN码。使用callback异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
callback AsyncCallback<number> 回调函数。如果获取成功,err为null,data为与该系统帐号关联的SN码;否则为错误对象。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId.
12300003 Account not found.

示例: 获取ID为100的系统帐号关联的SN码

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.getSerialNumberForOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
    console.log('ger serialNumber err:' + JSON.stringify(err));
    console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
  });
} catch (e) {
  console.log('ger serialNumber exception: ' + JSON.stringify(e));
}

getSerialNumberForOsAccountLocalId9+

getSerialNumberForOsAccountLocalId(localId: number): Promise<number>

通过系统帐号ID获取与该系统帐号关联的SN码。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。

返回值:

类型 说明
Promise<number> Promise对象,返回与该系统帐号关联的SN码。

错误码:

错误码ID 错误信息
12300001 System service exception.
12300002 Invalid localId.
12300003 Account not found.

示例: 获取ID为100的系统帐号关联的SN码

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
try {
  accountManager.getSerialNumberForOsAccountLocalId(localId).then((serialNumber: number) => {
    console.log('getSerialNumberForOsAccountLocalId serialNumber: ' + serialNumber);
  }).catch((err: BusinessError) => {
    console.log('getSerialNumberForOsAccountLocalId err: ' + JSON.stringify(err));
  });
} catch (e) {
  console.log('getSerialNumberForOsAccountLocalId exception: ' + JSON.stringify(e));
}

isMultiOsAccountEnable(deprecated)

isMultiOsAccountEnable(callback: AsyncCallback<boolean>): void

判断是否支持多系统帐号。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用checkMultiOsAccountEnabled

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<boolean> 回调函数。返回true表示支持多系统帐号;返回false表示不支持。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.isMultiOsAccountEnable((err: BusinessError, isEnabled: boolean) => {
  if (err) {
    console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
  } else {
  console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
  }
});

isMultiOsAccountEnable(deprecated)

isMultiOsAccountEnable(): Promise<boolean>

判断是否支持多系统帐号。使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用checkMultiOsAccountEnabled

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示支持多系统帐号;返回false表示不支持。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.isMultiOsAccountEnable().then((isEnabled: boolean) => {
  console.log('isMultiOsAccountEnable successfully, isEnabled: ' + isEnabled);
}).catch((err: BusinessError) => {
  console.log('isMultiOsAccountEnable failed, error: ' + JSON.stringify(err));
});

isOsAccountActived(deprecated)

isOsAccountActived(localId: number, callback: AsyncCallback<boolean>): void

判断指定系统帐号是否处于激活状态。使用callback异步回调。

说明:

从 API version 7开始支持从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
callback AsyncCallback<boolean> 回调函数。返回true表示帐号已激活;返回false表示帐号未激活。

示例: 判断ID为100的系统帐号是否处于激活状态

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
accountManager.isOsAccountActived(localId, (err: BusinessError, isActived: boolean) => {
  if (err) {
    console.log('isOsAccountActived failed, err:' + JSON.stringify(err));
  } else {
    console.log('isOsAccountActived successfully, isActived:' + isActived);
  }
});

isOsAccountActived(deprecated)

isOsAccountActived(localId: number): Promise<boolean>

判断指定系统帐号是否处于激活状态。使用Promise异步回调。

说明:

从 API version 7开始支持从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示帐号已激活;返回false表示帐号未激活。

示例: 判断ID为100的系统帐号是否处于激活状态

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
accountManager.isOsAccountActived(localId).then((isActived: boolean) => {
  console.log('isOsAccountActived successfully, isActived: ' + isActived);
}).catch((err: BusinessError) => {
  console.log('isOsAccountActived failed, error: ' + JSON.stringify(err));
});

isOsAccountConstraintEnable(deprecated)

isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback<boolean>): void

判断指定系统帐号是否具有指定约束。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
constraint string 指定的约束名称。
callback AsyncCallback<boolean> 回调函数。返回true表示已使能指定的约束;返回false表示未使能指定的约束。

示例: 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
let constraint: string = 'constraint.wifi';
accountManager.isOsAccountConstraintEnable(localId, constraint, (err: BusinessError, isEnabled: boolean) => {
  if (err) {
    console.log('isOsAccountConstraintEnable failed, error: ' + JSON.stringify(err));
  } else {
    console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
  }
});

isOsAccountConstraintEnable(deprecated)

isOsAccountConstraintEnable(localId: number, constraint: string): Promise<boolean>

判断指定系统帐号是否具有指定约束。使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
constraint string 指定的约束名称。

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示已使能指定的约束;返回false表示未使能指定的约束。

示例: 判断ID为100的系统帐号是否有禁止使用Wi-Fi的约束

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
let constraint: string = 'constraint.wifi';
accountManager.isOsAccountConstraintEnable(localId, constraint).then((isEnabled: boolean) => {
  console.log('isOsAccountConstraintEnable successfully, isEnabled: ' + isEnabled);
}).catch((err: BusinessError) => {
  console.log('isOsAccountConstraintEnable err: ' + JSON.stringify(err));
});

isTestOsAccount(deprecated)

isTestOsAccount(callback: AsyncCallback<boolean>): void

检查当前系统帐号是否为测试帐号。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用checkOsAccountTestable

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<boolean> 回调函数。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.isTestOsAccount((err: BusinessError, isTestable: boolean) => {
  if (err) {
    console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
  } else {
    console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
  }
});

isTestOsAccount(deprecated)

isTestOsAccount(): Promise<boolean>

检查当前系统帐号是否为测试帐号。使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用checkOsAccountTestable

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示当前帐号为测试帐号;返回false表示当前帐号非测试帐号。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
  accountManager.isTestOsAccount().then((isTestable: boolean) => {
    console.log('isTestOsAccount successfully, isTestable: ' + isTestable);
  }).catch((err: BusinessError) => {
    console.log('isTestOsAccount failed, error: ' + JSON.stringify(err));
});

isOsAccountVerified(deprecated)

isOsAccountVerified(callback: AsyncCallback<boolean>): void

检查当前系统帐号是否已验证。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用checkOsAccountVerified

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<boolean> 回调函数。返回true表示指定帐号已验证;返回false表示指定帐号未验证。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.isOsAccountVerified((err: BusinessError, isVerified: boolean) => {
  if (err) {
    console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
  } else {
    console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
  }
});

isOsAccountVerified(deprecated)

isOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void

检查指定系统帐号是否已验证。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
callback AsyncCallback<boolean> 回调函数。返回true表示指定帐号已验证;返回false表示指定帐号未验证。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
accountManager.isOsAccountVerified(localId, (err: BusinessError, isVerified: boolean) => {
  if (err) {
    console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
  } else {
    console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
  }
});

isOsAccountVerified(deprecated)

isOsAccountVerified(localId?: number): Promise<boolean>

检查指定系统帐号是否已验证。使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS,以上权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。不填则检查当前系统帐号是否已验证。

返回值:

类型 说明
Promise<boolean> Promise对象。返回true表示指定帐号已验证;返回false表示指定帐号未验证。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.isOsAccountVerified().then((isVerified: boolean) => {
  console.log('isOsAccountVerified successfully, isVerified: ' + isVerified);
}).catch((err: BusinessError) => {
  console.log('isOsAccountVerified failed, error: ' + JSON.stringify(err));
});

getCreatedOsAccountsCount(deprecated)

getCreatedOsAccountsCount(callback: AsyncCallback<number>): void

获取已创建的系统帐号数量。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountCount

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<number> 回调函数。当获取成功时,err为null,data为已创建的系统帐号的数量;否则为错误对象。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.getCreatedOsAccountsCount((err: BusinessError, count: number)=>{
  if (err) {
    console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
  } else {
    console.log('getCreatedOsAccountsCount successfully, count: ' + count);
  }
});

getCreatedOsAccountsCount(deprecated)

getCreatedOsAccountsCount(): Promise<number>

获取已创建的系统帐号数量,使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountCount

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<number> Promise对象,返回已创建的系统帐号的数量。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.getCreatedOsAccountsCount().then((count: number) => {
  console.log('getCreatedOsAccountsCount successfully, count: ' + count);
}).catch((err: BusinessError) => {
  console.log('getCreatedOsAccountsCount failed, error: ' + JSON.stringify(err));
});

getOsAccountLocalIdFromProcess(deprecated)

getOsAccountLocalIdFromProcess(callback: AsyncCallback<number>): void

获取当前进程所属的系统帐号ID,使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountLocalId

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<number> 回调函数。当获取成功时,err为null,data为当前进程所属的系统帐号ID;否则为错误对象。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountLocalIdFromProcess((err: BusinessError, localId: number) => {
  if (err) {
    console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
  } else {
    console.log('getOsAccountLocalIdFromProcess failed, error: ' + localId);
  }
});

getOsAccountLocalIdFromProcess(deprecated)

getOsAccountLocalIdFromProcess(): Promise<number>

获取当前进程所属的系统帐号ID,使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountLocalId

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<number> Promise对象,返回当前进程所属的系统帐号ID。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountLocalIdFromProcess().then((localId: number) => {
  console.log('getOsAccountLocalIdFromProcess successfully, localId: ' + localId);
}).catch((err: BusinessError) => {
  console.log('getOsAccountLocalIdFromProcess failed, error: ' + JSON.stringify(err));
});

getOsAccountLocalIdFromUid(deprecated)

getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback<number>): void

根据uid查询对应的系统帐号ID。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForUid

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
uid number 进程uid。
callback AsyncCallback<number> 回调函数。如果查询成功,err为null,data为对应的系统帐号ID;否则为错误对象。

示例: 查询值为12345678的uid所属的系统帐号ID

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let uid: number = 12345678;
accountManager.getOsAccountLocalIdFromUid(uid, (err: BusinessError, localId: number) => {
  if (err) {
    console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
  } else {
    console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
  }
});

getOsAccountLocalIdFromUid(deprecated)

getOsAccountLocalIdFromUid(uid: number): Promise<number>

根据uid查询对应的系统帐号ID,使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForUid

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
uid number 进程uid。

返回值:

类型 说明
Promise<number> Promise对象,返回uid对应的系统帐号ID。

示例: 查询值为12345678的uid所属的系统帐号ID

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let uid: number = 12345678;
accountManager.getOsAccountLocalIdFromUid(uid).then((localId: number) => {
  console.log('getOsAccountLocalIdFromUid successfully, localId: ' + localId);
}).catch((err: BusinessError) => {
  console.log('getOsAccountLocalIdFromUid failed, error: ' + JSON.stringify(err));
});

getOsAccountLocalIdFromDomain(deprecated)

getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void

根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用callback异步回调。

说明:

从 API version 8开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForDomain

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
domainInfo DomainAccountInfo 域帐号信息。
callback AsyncCallback<number> 回调函数,如果获取成功,err为null,data为域帐号关联的系统帐号ID;否则为错误对象。

示例:

import { BusinessError } from '@ohos.base';
let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err: BusinessError, localId: number) => {
  if (err) {
    console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
  } else {
    console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
  }
});

getOsAccountLocalIdFromDomain(deprecated)

getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise<number>

根据域帐号信息,获取与其关联的系统帐号的帐号ID。使用Promise异步回调。

说明:

从 API version 8开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForDomain

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
domainInfo DomainAccountInfo 域帐号信息。

返回值:

类型 说明
Promise<number> Promise对象,返回域帐号关联的系统帐号ID。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let domainInfo: account_osAccount.DomainAccountInfo = {domain: 'testDomain', accountName: 'testAccountName'};
accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((localId: number) => {
  console.log('getOsAccountLocalIdFromDomain successfully, localId: ' + localId);
}).catch((err: BusinessError) => {
  console.log('getOsAccountLocalIdFromDomain failed, error: ' + JSON.stringify(err));
});

getOsAccountAllConstraints(deprecated)

getOsAccountAllConstraints(localId: number, callback: AsyncCallback<Array<string>>): void

获取指定系统帐号的全部约束。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
callback AsyncCallback<Array<string>> 回调函数。如果获取成功,err为null,data为指定系统帐号的全部约束;否则为错误对象。

示例: 获取ID为100的系统帐号的全部约束

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
accountManager.getOsAccountAllConstraints(localId, (err: BusinessError, constraints: string[])=>{
  console.log('getOsAccountAllConstraints err:' + JSON.stringify(err));
  console.log('getOsAccountAllConstraints:' + JSON.stringify(constraints));
});

getOsAccountAllConstraints(deprecated)

getOsAccountAllConstraints(localId: number): Promise<Array<string>>

获取指定系统帐号的全部约束。使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。

返回值:

类型 说明
Promise<Array<string>> Promise对象,返回指定系统帐号的全部约束

示例: 获取ID为100的系统帐号的全部约束

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
accountManager.getOsAccountAllConstraints(localId).then((constraints: string[]) => {
  console.log('getOsAccountAllConstraints, constraints: ' + constraints);
}).catch((err: BusinessError) => {
  console.log('getOsAccountAllConstraints err: ' + JSON.stringify(err));
});

queryActivatedOsAccountIds(deprecated)

queryActivatedOsAccountIds(callback: AsyncCallback<Array<number>>): void

查询当前处于激活状态的系统帐号的ID列表。使用callback异步回调。

说明:

从 API version 8开始支持,从API version 9开始废弃。建议使用getActivatedOsAccountLocalIds

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<Array<number>> 回调函数。如果查询成功,err为null,data为当前处于激活状态的系统帐号的ID列表;否则为错误对象。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.queryActivatedOsAccountIds((err: BusinessError, idArray: number[])=>{
  console.log('queryActivatedOsAccountIds err:' + JSON.stringify(err));
  console.log('queryActivatedOsAccountIds idArray length:' + idArray.length);
  for(let i=0;i<idArray.length;i++) {
    console.info('activated os account id: ' + idArray[i]);
  }
});

queryActivatedOsAccountIds(deprecated)

queryActivatedOsAccountIds(): Promise<Array<number>>

说明:

从 API version 8开始支持,从API version 9开始废弃。建议使用getActivatedOsAccountLocalIds

查询当前处于激活状态的系统帐号的ID列表。使用Promise异步回调。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<Array<number>> Promise对象,返回当前处于激活状态的系统帐号的ID列表。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.queryActivatedOsAccountIds().then((idArray: number[]) => {
  console.log('queryActivatedOsAccountIds, idArray: ' + idArray);
}).catch((err: BusinessError) => {
  console.log('queryActivatedOsAccountIds err: ' + JSON.stringify(err));
});

queryCurrentOsAccount(deprecated)

queryCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void

查询当前进程所属的系统帐号的信息。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<OsAccountInfo> 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号信息;否则为错误对象。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.queryCurrentOsAccount((err: BusinessError, curAccountInfo: account_osAccount.OsAccountInfo)=>{
  console.log('queryCurrentOsAccount err:' + JSON.stringify(err));
  console.log('queryCurrentOsAccount curAccountInfo:' + JSON.stringify(curAccountInfo));
});

queryCurrentOsAccount(deprecated)

queryCurrentOsAccount(): Promise<OsAccountInfo>

查询当前进程所属的系统帐号的信息。使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。替代方法仅向系统应用开放。

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS,该权限仅系统应用可申请。

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<OsAccountInfo> Promise对象,返回当前进程所属的系统帐号信息。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.queryCurrentOsAccount().then((accountInfo: account_osAccount.OsAccountInfo) => {
  console.log('queryCurrentOsAccount, accountInfo: ' + JSON.stringify(accountInfo));
}).catch((err: BusinessError) => {
  console.log('queryCurrentOsAccount err: ' + JSON.stringify(err));
});

getOsAccountTypeFromProcess(deprecated)

getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): void

查询当前进程所属的系统帐号的帐号类型。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountType

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<OsAccountType> 回调函数。如果查询成功,err为null,data为当前进程所属的系统帐号的帐号类型;否则为错误对象。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountTypeFromProcess((err: BusinessError, accountType: account_osAccount.OsAccountType) => {
  console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
  console.log('getOsAccountTypeFromProcess accountType: ' + accountType);
});

getOsAccountTypeFromProcess(deprecated)

getOsAccountTypeFromProcess(): Promise<OsAccountType>

查询当前进程所属的系统帐号的帐号类型。使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用getOsAccountType

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<OsAccountType> Promise对象,返回当前进程所属的系统帐号的帐号类型。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.getOsAccountTypeFromProcess().then((accountType: account_osAccount.OsAccountType) => {
  console.log('getOsAccountTypeFromProcess, accountType: ' + accountType);
}).catch((err: BusinessError) => {
  console.log('getOsAccountTypeFromProcess err: ' + JSON.stringify(err));
});

getDistributedVirtualDeviceId(deprecated)

getDistributedVirtualDeviceId(callback: AsyncCallback<string>): void

获取分布式虚拟设备ID。使用callback异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用queryDistributedVirtualDeviceId

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS(仅系统应用可申请)或 ohos.permission.DISTRIBUTED_DATASYNC

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
callback AsyncCallback<string> 回调函数。如果获取成功,err为null,data为分布式虚拟设备ID;否则为错误对象。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.getDistributedVirtualDeviceId((err: BusinessError, virtualID: string) => {
  console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
  console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID);
});

getDistributedVirtualDeviceId(deprecated)

getDistributedVirtualDeviceId(): Promise<string>

获取分布式虚拟设备ID。使用Promise异步回调。

说明:

从 API version 7开始支持,从API version 9开始废弃。建议使用queryDistributedVirtualDeviceId

需要权限: ohos.permission.MANAGE_LOCAL_ACCOUNTS(仅系统应用可申请)或 ohos.permission.DISTRIBUTED_DATASYNC

系统能力: SystemCapability.Account.OsAccount

返回值:

类型 说明
Promise<string> Promise对象,返回分布式虚拟设备ID。

示例:

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
accountManager.getDistributedVirtualDeviceId().then((virtualID: string) => {
  console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID);
}).catch((err: BusinessError) => {
  console.log('getDistributedVirtualDeviceId err: ' + JSON.stringify(err));
});

getOsAccountLocalIdBySerialNumber(deprecated)

getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback<number>): void

通过SN码查询与其关联的系统帐号的帐号ID。使用callback异步回调。

说明:

从 API version 8开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForSerialNumber

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
serialNumber number 帐号SN码。
callback AsyncCallback<number> 回调函数。如果查询成功,err为null,data为与SN码关联的系统帐号的帐号ID;否则为错误对象。

示例: 查询与SN码12345关联的系统帐号的ID

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let serialNumber: number = 12345;
accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err: BusinessError, localId: number)=>{
  console.log('ger localId err:' + JSON.stringify(err));
  console.log('get localId:' + localId + ' by serialNumber: ' + serialNumber);
});

getOsAccountLocalIdBySerialNumber(deprecated)

getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise<number>

通过SN码查询与其关联的系统帐号的帐号ID。使用Promise异步回调。

说明:

从 API version 8开始支持,从API version 9开始废弃。建议使用getOsAccountLocalIdForSerialNumber

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
serialNumber number 帐号SN码。

返回值:

类型 说明
Promise<number> Promise对象,返回与SN码关联的系统帐号的帐号ID。

示例: 查询与SN码12345关联的系统帐号的ID

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let serialNumber: number = 12345;
accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId: number) => {
  console.log('getOsAccountLocalIdBySerialNumber localId: ' + localId);
}).catch((err: BusinessError) => {
  console.log('getOsAccountLocalIdBySerialNumber err: ' + JSON.stringify(err));
});

getSerialNumberByOsAccountLocalId(deprecated)

getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void

通过系统帐号ID获取与该系统帐号关联的SN码。使用callback异步回调。

说明:

从 API version 8开始支持,从API version 9开始废弃。建议使用getSerialNumberForOsAccountLocalId

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。
callback AsyncCallback<number> 回调函数。如果获取成功,err为null,data为与该系统帐号关联的SN码;否则为错误对象。

示例: 获取ID为100的系统帐号关联的SN码

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
accountManager.getSerialNumberByOsAccountLocalId(localId, (err: BusinessError, serialNumber: number)=>{
  console.log('ger serialNumber err:' + JSON.stringify(err));
  console.log('get serialNumber:' + serialNumber + ' by localId: ' + localId);
});

getSerialNumberByOsAccountLocalId(deprecated)

getSerialNumberByOsAccountLocalId(localId: number): Promise<number>

通过系统帐号ID获取与该系统帐号关联的SN码。使用Promise异步回调。

说明:

从 API version 8开始支持,从API version 9开始废弃。建议使用getSerialNumberForOsAccountLocalId

系统能力: SystemCapability.Account.OsAccount

参数:

参数名 类型 必填 说明
localId number 系统帐号ID。

返回值:

类型 说明
Promise<number> Promise对象,返回与该系统帐号关联的SN码。

示例: 获取ID为100的系统帐号关联的SN码

import { BusinessError } from '@ohos.base';
let accountManager: account_osAccount.AccountManager = account_osAccount.getAccountManager();
let localId: number = 100;
accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber: number) => {
  console.log('getSerialNumberByOsAccountLocalId serialNumber: ' + serialNumber);
}).catch((err: BusinessError) => {
  console.log('getSerialNumberByOsAccountLocalId err: ' + JSON.stringify(err));
});

OsAccountInfo

表示系统帐号信息。

系统能力: SystemCapability.Account.OsAccount

名称 类型 必填 说明
localId number 系统帐号ID。
localName string 系统帐号名称。
type OsAccountType 系统帐号类型。
constraints Array<string> 系统帐号约束,默认为空。
isVerified(deprecated) boolean 帐号是否验证。
说明: 从API version 7开始支持,从API version 11开始废弃。
isUnlocked11+ boolean 帐号是否已解锁(EL2级别目录是否解密)。
photo8+ string 系统帐号头像,默认为空。
createTime8+ number 系统帐号创建时间。
lastLoginTime8+ number 系统帐号最后一次登录时间,默认为空。
serialNumber8+ number 系统帐号SN码。
isActived(deprecated) boolean 系统帐号激活状态。
说明: 从API version 7开始支持,从API version 11开始废弃。
isActivated11+ boolean 系统帐号激是否激活。
isCreateCompleted8+ boolean 系统帐号创建是否完整。
distributedInfo distributedAccount.DistributedInfo 分布式帐号信息,默认为空。
domainInfo8+ DomainAccountInfo 域帐号信息,默认为空。

DomainAccountInfo8+

表示域帐号信息。

系统能力: SystemCapability.Account.OsAccount

名称 类型 必填 说明
domain string 域名。
accountName string 域帐号名。

系统帐号约束列表

约束 说明
constraint.wifi 禁止使用Wi-Fi
constraint.wifi.set 禁止配置Wi-Fi
constraint.locale.set 禁止配置设备语言
constraint.app.accounts 禁止添加和删除应用帐号
constraint.apps.install 禁止安装应用
constraint.apps.uninstall 禁止卸载应用
constraint.location.shared 禁止打开位置共享
constraint.unknown.sources.install 禁止安装未知来源的应用
constraint.global.unknown.app.install 禁止所有用户安装未知来源的应用
constraint.bluetooth.set 禁止配置蓝牙
constraint.bluetooth 禁止使用蓝牙
constraint.bluetooth.share 禁止共享使用蓝牙
constraint.usb.file.transfer 禁止通过USB传输文件
constraint.credentials.set 禁止配置用户凭据
constraint.os.account.remove 禁止删除用户
constraint.managed.profile.remove 禁止删除此用户的托管配置文件
constraint.debug.features.use 禁止启用或访问调试功能
constraint.vpn.set 禁止配置VPN
constraint.date.time.set 禁止配置日期时间和时区
constraint.tethering.config 禁止配置Tethering
constraint.network.reset 禁止重置网络设置
constraint.factory.reset 禁止出厂设置
constraint.os.account.create 禁止创建新用户
constraint.add.managed.profile 禁止添加托管配置文件
constraint.apps.verify.disable 强制应用程序验证
constraint.cell.broadcasts.set 禁止配置小区广播
constraint.mobile.networks.set 禁止配置移动网络
constraint.control.apps 禁止在设置或启动模块中修改应用程序
constraint.physical.media 禁止装载物理外部介质
constraint.microphone 禁止使用麦克风
constraint.microphone.unmute 禁止取消麦克风静音
constraint.volume.adjust 禁止调整音量
constraint.calls.outgoing 禁止拨打外呼电话
constraint.sms.use 禁止发送或接收短信
constraint.fun 禁止享受乐趣
constraint.windows.create 禁止创建应用程序窗口以外的窗口
constraint.system.error.dialogs 禁止显示崩溃或无响应应用程序的系统错误对话框
constraint.cross.profile.copy.paste 禁止通过将数据粘贴到其他用户或配置文件来导出剪贴板内容
constraint.beam.outgoing 禁止使用NFC从应用程序传送数据
constraint.wallpaper 禁止管理壁纸
constraint.safe.boot 禁止进入安全引导模式
constraint.parent.profile.app.linking 允许父配置文件中的应用程序处理来自托管配置文件的Web链接
constraint.audio.record 禁止录制音频
constraint.camera.use 禁止使用摄像机
constraint.os.account.background.run 禁止在后台运行
constraint.data.roam 禁止漫游通话时使用蜂窝数据
constraint.os.account.set.icon 禁止修改用户头像
constraint.wallpaper.set 禁止设置壁纸
constraint.oem.unlock 禁止启用oem解锁
constraint.device.unmute 禁止取消设备静音
constraint.password.unified 禁止托管配置文件与主用户进行统一锁屏质询
constraint.autofill 禁止使用自动填充服务
constraint.content.capture 禁止捕获用户屏幕
constraint.content.suggestions 禁止接收内容建议
constraint.os.account.activate 禁止前台启动用户
constraint.location.set 禁止配置位置服务
constraint.airplane.mode.set 禁止飞行模式
constraint.brightness.set 禁止配置亮度
constraint.share.into.profile 禁止将主要用户的文件/图片/数据共享到托管配置文件中
constraint.ambient.display 禁止显示环境
constraint.screen.timeout.set 禁止配置屏幕关闭的超时
constraint.print 禁止打印
constraint.private.dns.set 禁止配置专用DNS