目录

AuthAccount

Class Info

public class AuthAccount

登录的帐号信息,包含ID、显示名称、头像URI、权限等信息。

Public Field Summary

Qualifier and Type

Field and Description

static final Creator<AuthAccount>

CREATOR

AuthAccount的创建者对象。

Public Constructor Summary

Constructor Name

AuthAccount()

默认的构造方法。

Public Method Summary

Qualifier and Type

Method Name and Description

static AuthAccount

createDefault()

构造一个AuthAccount空对象,其属性值都为空。

String

getAccessToken()

返回用户的AccessToken。

注意:

该方法已废弃。

Account

getAccount(Context context)

从帐号信息中获取Account。

String

getDisplayName()

从帐号信息中获取昵称。

String

getEmail()

从帐号信息中获取Email。

String

@Deprecated

getFamilyName()

从帐号信息中获取FamilyName。(此方法已废弃)

String

@Deprecated

getGivenName()

从帐号信息中获取GivenName。(此方法已废弃)

Set<Scope>

getAuthorizedScopes()

从帐号信息中获取已经授权的Scope。

String

getIdToken()

从帐号信息中获取ID Token。

Uri

getAvatarUri()

从帐号信息中获取头像URI。

String

getAuthorizationCode()

从帐号信息中获取授权码code。

String

getServiceCountryCode()

获取当前帐号所属的服务地国家。

String

getUnionId()

从帐号信息中获取UnionID。

String

getOpenId()

从帐号信息中获取OpenID。

int

getAccountFlag()

获取帐号类型。

int

getCarrierId()

获取运营商ID。

Public Constructors

[h2]AuthAccount

Constructor

AuthAccount()

默认的构造方法。

Public Methods

[h2]createDefault

Method

public static AuthAccount createDefault()

构造一个AuthAccount空对象,其属性值都为空。

Returns

Type

Description

AuthAccount

一个属性值都为空的AuthAccount对象。

[h2]getAccessToken

该方法已废弃。

Method

public String getAccessToken()

从帐号信息中获取Access Token。

Returns

Type

Description

String

Access Token。

[h2]getAccount

Method

public Account getAccount(Context context)

使用Email生成android.accounts.Account对象,Email由getEmail获取。

Parameters

Name

Description

context

上下文。

Returns

Type

Description

android.accounts.Account

Account对象。

[h2]getServiceCountryCode

Method

public String getServiceCountryCode()

获取当前帐号所属的服务地国家码。

Returns

Type

Description

String

服务地国家码。

[h2]getDisplayName

Method

public String getDisplayName()

如果授权时携带AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)或者setProfile指定的授权参数,该方法返回授权用户的帐号昵称,否则返回null。

Returns

Type

Description

String

昵称。

[h2]getEmail

Method

public String getEmail()

如果授权时携带setEmail指定的授权参数,该方法返回授权用户的Email地址,否则返回null。

Returns

Type

Description

String

帐号的Email地址。

[h2]getFamilyName

Method

@Deprecated

public String getFamilyName()

如果授权时携带AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)或者setProfile指定的授权参数,该方法返回授权用户的FamilyName,否则返回null。(此方法已废弃)

Returns

Type

Description

String

帐号的FamilyName。

[h2]getGivenName

Method

@Deprecated

public String getGivenName()

如果授权时携带AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)或者setProfile指定的授权参数,该方法返回授权用户的GivenName,否则返回null。(此方法已废弃)

Returns

Type

Description

String

帐号的GivenName。

[h2]getAuthorizedScopes

Method

public Set<Scope> getAuthorizedScopes()

获取用户授权给当前应用的所有Scope或当前业务请求中传入的Scope。

用户授权的Scope数量可能会比应用通过getSignInIntent或silentSignIn请求获取的Scope数量多,建议业务按需授权。

  • 如果存在授权缓存信息,则获取用户授权给当前应用的所有Scope。
  • 如果不存在授权缓存信息(调用signOut或者在应用管理中清除应用缓存),则获取当前业务请求中传入的Scope。

Returns

Type

Description

Set<Scope>

用户授权给当前应用的所有Scope。

[h2]getIdToken

Method

public String getIdToken()

如果授权时携带setIdToken指定的授权参数,该方法返回授权用户的ID Token,否则返回null。

Returns

Type

Description

String

返回授权用户的ID Token。

[h2]getAvatarUri

Method

public Uri getAvatarUri()

如果授权时携带AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)或者setProfile指定的授权参数,该方法返回授权用户头像的URI地址,否则返回null。

Returns

Type

Description

Uri

返回授权用户头像的URI地址。

[h2]getAuthorizationCode

Method

public String getAuthorizationCode()

如果授权时携带setAuthorizationCode指定的授权参数,该方法返回用户的Authorization Code,否则返回null。应用可以使用Authorization Code从帐号服务器获取ID Token和Access Token。

Returns

Type

Description

String

返回用户的Authorization Code。

[h2]getUnionId

Method

public String getUnionId()

如果授权时携带setId指定的授权参数,该方法返回用户的UnionID,否则返回null。

UnionID是用户在开发者多个应用中的唯一标志,对于同一个用户,同一个开发者帐号下管理的不同应用,UnionID值相同。如果一个应用转移到另外一个开发者帐号后,UnionID值也会变化。当前固定长度46,最大允许长度64,需进行三倍冗余考虑,不推荐进行长度限制。

UnionID和OpenID的区别在于,如果开发者帐号下管理了多个应用,针对同一个帐号,不同的应用返回的OpenID值不同,但返回的UnionID相同。如果您需要在不同应用中共享同一个帐号的用户信息,可以使用UnionID作为用户标识。

使用UnionID作为用户标识需要满足以下所有条件,如果任一不满足则不会返回:

  • 应用集成Account SDK 4.0.4以及更高版本。
  • HMS Core APK版本为4.0.4以及更高版本。
  • 应用启用了UnionID。

Returns

Type

Description

String

获取用户的union ID。

[h2]getOpenId

Method

public String getOpenId()

如果授权时携带setId指定的授权参数,该方法返回OpenID,否则返回null。

用户在应用中的唯一标识。同一个用户在不同应用下,OpenID值不同。使用OpenID标识用户,多个应用之间同一个帐号用户在开发者系统内会被标识为多个用户。当前非固定长度,最大允许长度256,需进行三倍冗余考虑,不推荐进行长度限制。

Returns

Type

Description

String

获取用户的open ID。

[h2]getAccountFlag

Method

public int getAccountFlag()

获取帐号类型,该方法返回accountFlag。

Returns

Type

Description

int

获取用户的account Flag。

  • 0:表示华为帐号。
  • 1:表示AppTouch帐号。

[h2]getCarrierId

Method

public int getCarrierId()

获取运营商ID。

Returns

Type

Description

int

获取运营商ID。