Last Updated on : 2024-11-18 11:33:12download
Tuya Developer Platform supports user management. For example, bind users, modify user information, process session expiration, and delete users.
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. |
The email address of the user. | |
callback | The callback. |
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. |
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 TuyaHomeSdk.getUserInstance().getUser().getSid() to get the value. |
callback | The callback. |
Example
// Returns a verification code to an email address.
TuyaHomeSdk.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.
TuyaHomeSdk.getUserInstance().bindEmail("86", "123456@123.com","123456", TuyaHomeSdk.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();
}
});
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
TuyaHomeSdk.getUserInstance().uploadUserAvatar(
file,
new IBooleanCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String code, String error) {
}
});
API description
void setTempUnit(TempUnitEnum unit, IResultCallback callback);
Parameter | Description |
---|---|
unit | The unit of temperature. Valid values:
|
callback | The callback. |
API description
void updateNickName(String name, final IReNickNameCallback callback);
Parameters
Parameter | Description |
---|---|
name | The nickname. |
callback | The callback. |
Example
TuyaHomeSdk.getUserInstance().updateNickName(nickName,
new IReNickNameCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String code, String error) {
}
});
API description
void updateTimeZone(String timezoneId, IResultCallback callback);
Parameters
Parameter | Description |
---|---|
timezoneId | The time zone ID. Example: Asia/Shanghai . |
callback | The callback. |
Example
TuyaHomeSdk.getUserInstance().updateTimeZone(
timezoneId,
new IResultCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String code, String error) {
}
});
Reports the location of the current user as required.
TuyaSdk.setLatAndLong(lat,lon);
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
TuyaHomeSdk.getUserInstance().updateUserInfo(new IResultCallback() {
@Override
public void onError(String code, String error) {
}
@Override
public void onSuccess() {
User user = TuyaHomeSdk.getUserInstance().getUser();
}
});
Logs out of an anonymous account or other types of accounts.
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
TuyaHomeSdk.getUserInstance().touristLogOut(new ILogoutCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(String code, String error) {
}
});
Example for Java
TuyaHomeSdk.getUserInstance().logout(new ILogoutCallback() {
@Override
public void onSuccess() {
// Logout is successful.
}
@Override
public void onError(String errorCode, String errorMsg) {
}
});
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
TuyaHomeSdk.getUserInstance().cancelAccount(new IResultCallback() {
@Override
public void onError(String code, String error) {
}
@Override
public void onSuccess() {
}
});
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 instructs the user to log in again.
API description
TuyaHomeSdk.setOnNeedLoginListener(INeedLoginListener needLoginListener);
Callback
needLoginListener.onNeedLogin(Context context);
Example
TuyaHomeSdk.setOnNeedLoginListener(new INeedLoginListener() {
@Override
public void onNeedLogin(Context context) {
}
});
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback