If you want your app to support Account Kit, complete the integration preparation by referring to Preparations.
The preparations include the following:
In the To HMS API scenario, if the getToken methods in the GoogleAuthUtil class are used, the methods need to be converted as follows.
Type | GoogleAuthUtil in Google APIs | To HMS API |
|---|---|---|
Class path | com.google.android.gms.auth.GoogleAuthUtil | com.huawei.hms.support.hwid.tools.HuaweiIdAuthTool |
Method | String getToken(Context context, Account account, String scope, Bundle extras) | String requestAccessToken(Context context, Account huaweiAccount, List<Scope> scopeList, Bundle extendInfo) |
Method | String getToken(Context context, Account account, String scope) | String requestAccessToken(Context context, Account huaweiAccount, List<Scope> scopeList) |
Method | String getToken(Context context, String accountName, String scope, Bundle extras) | String requestAccessToken(Context context, String huaweiAccountName, List<Scope> scopeList, Bundle bundle) |
Method | String getToken(Context context, String accountName, String scope) | String requestAccessToken(Context context, String huaweiAccountName, List<Scope> scopeList) |
The scope parameter in GoogleAuthUtil.getToken needs to be converted to the corresponding Scope of Account Kit and added to List as a parameter passed to HuaweiIdAuthTool.requestAccessToken.
When you use the getAccountForScopes method of the com.google.android.gms.auth.api.signin.GoogleSignIn class, the method needs to be converted as follows.
GoogleSignInAccount account = GoogleSignIn.getAccountForScopes(this, scope);
ExtensionSignInAccount account = null;
com.google.android.gms.auth.api.signin.GoogleSignInAccount gReturn = null;
com.huawei.hms.support.hwid.result.AuthHuaweiId hReturn = null;
if (org.xms.g.utils.GlobalEnvSetting.isHms()) {
List<com.huawei.hms.support.api.entity.auth.Scope> scopeList = new ArrayList<>();
scopeList.add((com.huawei.hms.support.api.entity.auth.Scope) scope.getHInstance());
try {
hReturn = com.huawei.hms.support.hwid.HuaweiIdAuthManager.getAuthResultWithScopes(scopeList);
} catch (com.huawei.hms.support.hwid.common.HuaweiIdAuthException e) {
// handle exception
}
} else {
gReturn = com.google.android.gms.auth.api.signin.GoogleSignIn.getAccountForScopes(this,
(com.google.android.gms.common.api.Scope) scope.getGInstance());
}
if (hReturn != null || gReturn != null) {
account = new org.xms.g.auth.api.signin.ExtensionSignInAccount(gReturn, hReturn);
} List<com.huawei.hms.support.api.entity.auth.Scope> scopeList = new ArrayList<>();
scopeList.add(scope);
try {
com.huawei.hms.support.hwid.result.AuthHuaweiId account =
com.huawei.hms.support.hwid.HuaweiIdAuthManager.getAuthResultWithScopes(scopeList);
} catch (com.huawei.hms.support.hwid.common.HuaweiIdAuthException e) {
// handle exception
} When you use the requestPermissions(Fragment, int, GoogleSignInAccount, GoogleSignInOptionsExtension) method of the com.google.android.gms.auth.api.signin.GoogleSignIn class, the method needs to be converted as follows.
GoogleSignIn.requestPermissions(fragment, RC_REQUEST_PERMISSION, googleSignInAccount, mGoogleSignInOptionsExtension);
ExtensionSignIn.requestPermissions(fragment.getActivity(), RC_REQUEST_PERMISSION, googleSignInAccount, mGoogleSignInOptionsExtension);
com.huawei.hms.support.hwid.HuaweiIdAuthManager.addAuthScopes(fragment.getActivity(), RC_REQUEST_PERMISSION, huaweiIdAuthExtendedParams);
When you use the requestPermissions(Fragment, int, GoogleSignInAccount, Scope...) method of the com.google.android.gms.auth.api.signin.GoogleSignIn class, the method needs to be converted as follows.
GoogleSignIn.requestPermissions(fragment, RC_REQUEST_PERMISSION, googleSignInAccount, scope);
ExtensionSignIn.requestPermissions(fragment.getActivity(), RC_REQUEST_PERMISSION, googleSignInAccount, scope);
List<com.huawei.hms.support.api.entity.auth.Scope> scopeList = new ArrayList<>(); scopeList.add(scope); com.huawei.hms.support.hwid.HuaweiIdAuthManager.addAuthScopes(fragment.getActivity(), RC_REQUEST_PERMISSION, scopeList);
In the To HMS API scenario, if the following methods in the GoogleSignIn class are used, the methods need to be converted as follows.
Type | GoogleSignIn in Google APIs | To HMS API |
|---|---|---|
Class path | com.google.android.gms.auth.api.signin.GoogleSignIn | com.huawei.hms.support.hwid.HuaweiIdAuthManager |
Method | GoogleSignInAccount getAccountForExtension(Context context, GoogleSignInOptionsExtension extension) | AuthAccount getExtendedAuthResult(AccountAuthExtendedParams huaweiIdAuthExtendedParams) |
Method | GoogleSignInAccount getLastSignedInAccount(Context context) | |
Method | boolean hasPermissions(GoogleSignInAccount account, Scope... scopes) | containScopes(AuthAccount authAccount, List<Scope> scopeList) |
Method | void requestPermissions(Activity activity, int requestCode, GoogleSignInAccount account, Scope... scopes) | void addAuthScopes(Activity activity, int requestCode, List<Scope> scopeList) |
Method | void requestPermissions(Activity activity, int requestCode, GoogleSignInAccount account, GoogleSignInOptionsExtension extension) | void addAuthScopes(Activity activity, int requestCode, AccountAuthExtendedParams huaweiIdAuthExtendedParams) |
The scopes parameters in GoogleSignIn.hasPermissions and GoogleSignIn.requestPermissions need to be converted to the corresponding Scope of Account Kit and added to List as parameters passed to HuaweiIdAuthManager.containScopes and HuaweiIdAuthManager.addAuthScopes.
If the SignInButton class is used in your code, convert the related methods as follows.
Type | SignInButton in Google APIs | Add HMS API | To HMS API |
|---|---|---|---|
Class path | com.google.android.gms.common.SignInButton | com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton | com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton |
Method | button.onClick(view) | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { button.performClick(); } else { button.onClick(view); } | button.performClick() |
Method | button.setColorScheme(colorScheme) | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { button.setColorPolicy(colorPolicy); } else { button.setColorScheme(colorScheme); } | button.setColorPolicy(colorPolicy) |
Method | button.setEnabled(true) | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { button.setEnabled(true); } else { button.setEnabled(true); } | button.setEnabled(true) |
Method | button.setOnClickListener(listener) | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { button.setOnClickListener(listener); } else { button.setOnClickListener(listener); } | button.setOnClickListener(listener) |
Method | button.setSize(buttonSize) | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { button.setTheme(theme); } else { button.setSize(buttonSize); } | button.setTheme(theme) |
Method | button.setStyle(buttonSize, colorScheme) | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { button.setUIMode(theme, colorPolicy, cornerRadiusPx); } else { button.setStyle(buttonSize, colorScheme); } | button.setUIMode(theme, colorPolicy, cornerRadiusPx) |
Method | SignInButton button = new SignInButton(context) | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton button = new com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton(context); } else { com.google.android.gms.common.SignInButton button = new com.google.android.gms.common.SignInButton(context); } | com.huawei.hms.support.hwid.uiHuaweiIdAuthButton button = new com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton(context) |
Method | SignInButton button = new SignInButton(context, attributes) | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton button = new com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton(context, attributes); } else { com.google.android.gms.common.SignInButton button = new com.google.android.gms.common.SignInButton(context, attributes); } | com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton button = new com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton(context, attributes) |
Method | SignInButton button = new SignInButton(context, attributes, defStyle) | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton button = new com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton(context, attributes, defStyle); } else { com.google.android.gms.common.SignInButton button = new com.google.android.gms.common.SignInButton(context, attributes, defStyle); } | com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton button = new com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton(context, attributes, defStyle) |
Constant | int color = SignInButton.COLOR_AUTO | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { int color = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.COLOR_POLICY_BLUE; } else { int color = com.google.android.gms.common.SignInButton.COLOR_AUTO; } | int color = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.COLOR_POLICY_BLUE |
Constant | int color = SignInButton.COLOR_DARK | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { int color = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.COLOR_POLICY_RED; } else { int color = com.google.android.gms.common.SignInButton.COLOR_DARK; } | int color = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.COLOR_POLICY_RED |
Constant | int color = SignInButton.COLOR_LIGHT | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { int color = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.COLOR_POLICY_WHITE; } else { int color = com.google.android.gms.common.SignInButton.COLOR_LIGHT; } | int color = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.COLOR_POLICY_WHITE |
Constant | int size = SignInButton.SIZE_ICON_ONLY | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { int theme = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.THEME_NO_TITLE; } else { int size = com.google.android.gms.common.SignInButton.SIZE_ICON_ONLY; } | int theme = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.THEME_NO_TITLE |
Constant | int size = SignInButton.SIZE_WIDE | if (org.xms.g.utils.GlobalEnvSetting.isHms()) { int theme = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.THEME_FULL_TITLE; } else { int size = com.google.android.gms.common.SignInButton.SIZE_WIDE; } | int theme = com.huawei.hms.support.hwid.ui.HuaweiIdAuthButton.THEME_FULL_TITLE |
When the setUIMode(int theme, int colorPolicy, int cornerRadiusPx) method is used, the cornerRadiusPx parameter indicates the round corner radius of the button. The default value HuaweiIdAuthButton.CORNER_RADIUS_MEDIUM can be passed.
In the To HMS API scenario, if the following methods in the GoogleSignInOptions class are used, the methods need to be converted as follows.
Type | GoogleSignInOptions in Google APIs | To HMS API |
|---|---|---|
Class path | com.google.android.gms.auth.api.signin.GoogleSignInOptions | com.huawei.hms.support.hwid.request.HuaweiIdAuthParams |
Method | Scope[] getScopeArray() | List<Scope> getRequestScopeList() |
In the To HMS API scenario, if the following methods in the GoogleSignInOptions.Builder class are used, the methods need to be converted as follows.
Type | GoogleSignInOptions.Builder in Google APIs | To HMS API |
|---|---|---|
Class path | com.google.android.gms.auth.api.signin.GoogleSignInOptions.Builder | com.huawei.hms.support.hwid.request.HuaweiIdAuthParamsHelper |
Method | GoogleSignInOptions.Builder requestIdToken(String serverClientId) | |
Method | GoogleSignInOptions.Builder requestScopes(Scope scope, Scope... scopes) | HuaweiIdAuthParamsHelper setScopeList(List<Scope> scopeList) |
Method | GoogleSignInOptions.Builder requestServerAuthCode(String serverClientId) |
The scopes parameter in GoogleSignInOptions.Builder.requestScopes needs to be converted to the corresponding Scope of Account Kit and added to List as a parameter passed to HuaweiIdAuthParamsHelper.setScopeList.
If the SmsRetriever class is used in your code, convert the related methods as follows.
Type | SmsRetriever in Google APIs | To HMS API |
|---|---|---|
Class path | com.google.android.gms.auth.api.phone.SmsRetriever | com.huawei.hms.support.sms.ReadSmsManager |
Method | Task<Void> task = SmsRetriever.getClient(mActivity).startSmsRetriever(); | com.huawei.hmf.tasks.Task<Void> task = com.huawei.hms.support.sms.ReadSmsManager.start(mActivity) |
Method | Task<Void> task = SmsRetriever.getClient(mContext).startSmsRetriever(); | com.huawei.hmf.tasks.Task<Void> task = com.huawei.hms.support.sms.ReadSmsManager.start(mContext) |
Method | Task<Void> task = SmsRetriever.getClient(mActivity).startSmsUserConsent(phoneNumer); | com.huawei.hmf.tasks.Task<Void> task = com.huawei.hms.support.sms.ReadSmsManager.startConsent(mActivity, phoneNumer); |
In the To HMS API scenario, if the following methods in the GoogleAuthUtil class are used in your code, certain exceptions need to be removed.
Method in the GoogleAuthUtil Class in Google APIs | Exception to Be Removed |
|---|---|
void clearToken(Context context, String token) | java.io.IOException |
String getAccountId(Context ctx, String accountName) | java.io.IOException |
String getToken(Context var0, Account var1, String var2) | java.io.IOException com.google.android.gms.auth.UserRecoverableAuthException |
String getToken(Context var0, Account var1, String var2, Bundle var3) | java.io.IOException com.google.android.gms.auth.UserRecoverableAuthException |
String getToken(Context var0, String var1, String var2) | java.io.IOException com.google.android.gms.auth.UserRecoverableAuthException |
String getToken(Context var0, String var1, String var2, Bundle var3) | java.io.IOException com.google.android.gms.auth.UserRecoverableAuthException |
If you use constants of Google APIs in a switch statement in your code, you need to change the statement to the if else statement. The reference conversion method is as follows.
switch (code) {
case CommonStatusCodes.SUCCESS:
// ...
case CommonStatusCodes.CANCELED:
// ...
} if (code == CommonStatusCodes.getSUCCESS()) {
// ...
} else if (code == CommonStatusCodes.getCANCELED()) {
// ...
}