Guide to integrating Google Sign-In on Android

更新时间:
复制 MD 格式

This topic describes how to integrate Google Sign-In on Android.

Preparations

To integrate Google Sign-In into your Android application, you must complete the required preparations. In addition to importing the Feiyan mobile SDK, follow the instructions in the official Google documentation. For more information, see Start integrating Google Sign-In into your Android app.

You must configure the Google API Console project.

After you configure the console project, obtain the client ID. For example: xxxxxxxx-7xxxxxxxoj2ef0b9pcecsmba.apps.googleusercontent.com.

Code development

After you complete the preparations, you can start developing the code. The SDK for white-label apps handles most of the complex logic.

Develop the code as follows:

  1. Set the client ID in the SDK for your white-label app.
    
    import com.alibaba.sdk.android.openaccount.ConfigManager;
    
    ConfigManager.getInstance().setGoogleClientId(your_google_client_id);
  2. Set the country before you start the Google Sign-In process.

    Setting the country specifies the Feiyan region to which the account connects. For more information, see General-purpose SDK.

  3. Start Google Sign-In

    The SDK encapsulates the launch of the Google logon page and the OAuth process. Simply call the following code.

    
    import com.aliyun.iot.aep.sdk.login.LoginBusiness;
    
                                // Third-party logon
      LoginBusiness.oauthLogin(LoginWelcomeActivity.this, new ILoginCallback() {
                                    @Override
                                    public void onLoginSuccess() {
                                        LoginUtils.registerSuccess(new WeakReference<Activity>(LoginWelcomeActivity.this));
                                    }
    
                                    @Override
                                    public void onLoginFailed(int i, String s) {
                                        LoginUtils.registerFail(new WeakReference<Activity>(LoginWelcomeActivity.this), i, s);
                                    }
                                });