Manage User Accounts

Last Updated on : 2023-09-20 12:35:37download

Smart Life App SDK supports user management. For example, bind users, modify user information, process session expiration, and delete users.

Bind email address with account

Send verification code

API description

void sendBindVerifyCodeWithEmail(@NonNull String countryCode, @NonNull String email, @NonNull IResultCallback callback);

Parameters

Parameter Description
countryCode The country code. For example, 86 means mainland China.
email The email address of the user.
callback The callback.

Bind email address

API description

void bindEmail(@NonNull String countryCode, @NonNull String email, @NonNull String code, @NonNull String sId, @NonNull IResultCallback callback);

Parameters

Parameter Description
countryCode The country code. For example, 86 means mainland China.
email The email address of the user.
code The verification code. You must call sendBindVerifyCodeWithEmail to send a verification code.
sId The session ID of the user. You can query the user data model ThingHomeSdk.getUserInstance().getUser().getSid() to get the value.
callback The callback.

Example

// Returns a verification code to an email address.
ThingHomeSdk.getUserInstance().sendBindVerifyCodeWithEmail("86","123456@123.com", new IResultCallback(){

    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        Toast.makeText(mContext, "Verification code returned successfully.", Toast.LENGTH_SHORT).show();
    }
});

// Binds the email address with the account.
ThingHomeSdk.getUserInstance().bindEmail("86", "123456@123.com","123456", ThingHomeSdk.getUserInstance().getUser().getSid(), new IResultCallback() {
    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        Toast.makeText(mContext, "Bound successfully.", Toast.LENGTH_SHORT).show();
    }
});

Change email address bound with account

API description

void changeUserName(String countryCode, String code, String sId, String userName, IResultCallback callback);

Parameters

Parameters Description
countryCode The country code. For example, 86 means mainland China.
code The verification code. You must call sendVerifyCodeWithUserName to send a verification code.
sId The session ID of a user account. You can get the value from the user data model ThingHomeSdk.getUserInstance().getUser().getSid().
userName The new email address bound with the user account.
callback The callback.

Example

// Returns a verification code to change the email address.
ThingHomeSdk.getUserInstance().sendVerifyCodeWithUserName("Send the verification code to the new email address to be bound the account.",ThingHomeSdk.getUserInstance().getUser().getDomain().getRegionCode(),"86",7, new IResultCallback(){

    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        Toast.makeText(mContext, "Verification code returned successfully.", Toast.LENGTH_SHORT).show();
    }
});

// Changes the email address bound with the user account.
ThingHomeSdk.getUserInstance().changeUserName("86", "123456", ThingHomeSdk.getUserInstance().getUser().getSid(), "123456@123.com",new IResultCallback() {
    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        Toast.makeText(mContext, "Bound successfully.", Toast.LENGTH_SHORT).show();
    }
});

Modify account information

Change a user avatar

Compliance issues and certain risks might be caused if users are allowed to upload a custom avatar. To protect you from these potential issues and risks, this API method is deprecated. Modify your app features accordingly and avoid using this API method.

API description

void uploadUserAvatar(File file, IBooleanCallback callback)

Parameters

Parameter Description
file The user avatar file.
callback The callback.

Example

ThingHomeSdk.getUserInstance().uploadUserAvatar(
    file,
    new IBooleanCallback() {
        @Override
        public void onSuccess() {
        }

        @Override
        public void onError(String code, String error) {

        }
});

Set temperature unit to Celsius or Fahrenheit

API description

void setTempUnit(TempUnitEnum unit, IResultCallback callback);
Parameter Description
unit The unit of temperature. Valid values:
  • TempUnitEnum.Celsius: °C
  • TempUnitEnum.Fahrenheit: °F
callback The callback.

Modify the nickname

API description

void updateNickName(String name, final IReNickNameCallback callback);

Parameters

Parameter Description
name The nickname.
callback The callback.

Example

ThingHomeSdk.getUserInstance().updateNickName(nickName,
    new IReNickNameCallback() {
        @Override
        public void onSuccess() {
        }
        @Override
        public void onError(String code, String error) {

        }
});

Update user’s time zone

API description

void updateTimeZone(String timezoneId, IResultCallback callback);

Parameters

Parameter Description
timezoneId The time zone ID. Example: Asia/Shanghai.
callback The callback.

Example

ThingHomeSdk.getUserInstance().updateTimeZone(
    timezoneId,
    new IResultCallback() {
        @Override
        public void onSuccess() {
        }

        @Override
        public void onError(String code, String error) {

        }
});

Update user’s location

Reports the location of the current user as required.

ThingSdk.setLatAndLong(lat,lon);

Synchronize users

Synchronizes the latest user information if user information such as the avatar or nickname is changed.

If the user is logged in from multiple mobile phones and one of the mobile phones has user information changed, the changes are synchronized to the other mobile phone when the user information is checked on the mobile phone.

API description

void updateUserInfo(IResultCallback callback);

Parameters

Parameter Description
callback The callback.

Example

ThingHomeSdk.getUserInstance().updateUserInfo(new IResultCallback() {
    @Override
    public void onError(String code, String error) {

    }

    @Override
    public void onSuccess() {
        User user = ThingHomeSdk.getUserInstance().getUser();
    }
});

Log out of account

Logs out of an anonymous account or other types of accounts.

Log out of an anonymous account

API description

Logs out of an anonymous account. This type of account is deleted immediately after logout.

void touristLogOut(final ILogoutCallback callback)

Parameters

Parameter Type Description
success ILogoutCallback The callback.

Example

ThingHomeSdk.getUserInstance().touristLogOut(new ILogoutCallback() {
    @Override
    public void onSuccess() {

    }
    @Override
    public void onError(String code, String error) {

    }
});

Log out of other types of accounts

Example for Java

ThingHomeSdk.getUserInstance().logout(new ILogoutCallback() {
  @Override
  public void onSuccess() {
    // Logout is successful.
  }

  @Override
  public void onError(String errorCode, String errorMsg) {
  }
});

Inactivate or delete account

API description

Deletes a user account. During the week following this delete operation, if the user is logged in again, the delete request is canceled. If not, the user is permanently disabled and all its information is deleted after this week.

void cancelAccount(IResultCallback callback);

Example

ThingHomeSdk.getUserInstance().cancelAccount(new IResultCallback() {
    @Override
    public void onError(String code, String error) {

    }
    @Override
    public void onSuccess() {

    }
});

Process session expiration

Guides users to exit and log in to the app again after a login session expires to recreate the session. A login session might expire if certain exceptions occur or the user has not logged in for a long period such as 45 days, and when the user resets the password or deletes the account.

We recommend that you register a listener for session expiration in Application. When this callback is triggered, you can enable navigation to the login page and instruct the user to log in again.

API description

ThingHomeSdk.setOnNeedLoginListener(INeedLoginListener needLoginListener);

Callback

needLoginListener.onNeedLogin(Context context);

Example

ThingHomeSdk.setOnNeedLoginListener(new INeedLoginListener() {
  @Override
  public void onNeedLogin(Context context) {

  }
});