Device Sharing

Last Updated on : 2023-05-22 06:38:26

A user can share a device in a home with other users in the same home so that the other users can control the device. The users who receive a sharing invitation can control the device by using their app account.

Each device can be simultaneously shared with up to 20 users.

Integrate with the class

Class name Description
ITuyaHomeDeviceShare Provides the capabilities to share devices.

Share devices

Share multiple devices and overwrite earlier sharing

Shares multiple devices to a specific user and overwrites earlier sharing with the user. Each device can be simultaneously shared with up to 20 users.

API description

void addShare(long homeId, String countryCode, final String userAccount, ShareIdBean bean, boolean autoSharing, final ITuyaResultCallback<SharedUserInfoBean> callback);

Parameters

Parameter Description
homeId The ID of the home to which the devices belong.
countryCode The country code. For example, 86 means mainland China.
userAccount The account of the user who receives a sharing invitation.
bean The list of device IDs for sharing.
autoSharing Specifies whether automatic sharing is enabled.
callback The success or failure callback. null cannot be returned.

The following table describes the data structure of ShareIdBean.

Parameter Type Description
devIds List<String> The list of device IDs for sharing.
meshIds List<String> The list of mesh device IDs for sharing.

Example

TuyaHomeSdk.getDeviceShareInstance().addShare(homeId, countryCode, userAccount,
                shareIdBean, autoSharing, new ITuyaResultCallback<SharedUserInfoBean>() {
                    @Override
                    public void onSuccess(SharedUserInfoBean sharedUserInfoBean) {}
                    @Override
                    public void onError(String errorCode, String errorMsg) {}
                });

Share multiple devices without overwriting earlier sharing

Shares multiple devices to a specific user and adds these devices following earlier sharing with the user. If devices have ever been shared with a specified user, the subsequent sharing query API methods can be called to get the target user ID. Then, pass this user ID in the current method to implement quick sharing with the user. Each device can be simultaneously shared with up to 20 users.

API description

void addShareWithMemberId(long memberId,List<String> devIds,IResultCallback callback);

Parameters

Parameter Description
memberId The ID of the user who receives the sharing invitation.
devIds The list of device IDs for sharing.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().addShareWithMemberId(userId, devIdList, new IResultCallback() {
            @Override
            public void onError(String errorCode, String errorMsg) {
            }
            @Override
            public void onSuccess() {
            }
});

Share devices

Shares one or more devices to a specific user and adds these devices following earlier sharing with the user. Each device can be simultaneously shared with up to 20 users.

API description

void addShareWithHomeId(long homeId, String countryCode, String userAccount, List<String> devIds, ITuyaResultCallback<SharedUserInfoBean> callback);

Parameters

Parameter Description
homeId The ID of the home to which the device belongs.
countryCode The country code. For example, 86 means mainland China.
userAccount The account of the target user who receives the sharing invitation.
devIds The list of device IDs for sharing.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().addShareWithHomeId(homeId, countryCode,
                userAccount, devsIdList, new ITuyaResultCallback<SharedUserInfoBean>() {
                    @Override
                    public void onSuccess(SharedUserInfoBean sharedUserInfoBean) {
                    }

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

Query sharing data

Query all users who initiate sharing invitations in a home

API description

void queryUserShareList(long homeId, final ITuyaResultCallback<List<SharedUserInfoBean>> callback);

Parameters

Parameter Description
homeId The home ID.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().queryUserShareList(homeId, new ITuyaResultCallback<List<SharedUserInfoBean>>() {
            @Override
            public void onSuccess(List<SharedUserInfoBean> sharedUserInfoBeans) {}
            @Override
            public void onError(String errorCode, String errorMsg) {}
        });

Query all users who receive sharing invitations in a home

API description

void queryShareReceivedUserList(final ITuyaResultCallback<List<SharedUserInfoBean>> callback);

Parameters

Parameter Description
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().queryShareReceivedUserList(new ITuyaResultCallback<List<SharedUserInfoBean>>() {
    @Override
    public void onSuccess(List<SharedUserInfoBean> sharedUserInfoBeans) {
    }
    @Override
    public void onError(String errorCode, String errorMsg) {
    }
});

Query all users who initiate sharing invitations in a home

API description

void getUserShareInfo(long memberId, final ITuyaResultCallback<ShareSentUserDetailBean> callback);

Parameters

Parameter Description
memberId The user ID.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().getUserShareInfo(mRelationId, new ITuyaResultCallback<ShareSentUserDetailBean>() {
                @Override
                public void onSuccess(ShareSentUserDetailBean shareSentUserDetailBean) {}
                @Override
                public void onError(String errorCode, String errorMsg) {}
            });

Query sharing details of a user who receives a sharing invitation

API description

void getReceivedShareInfo(long memberId, final ITuyaResultCallback<ShareReceivedUserDetailBean> callback);

Parameters

Parameter Description
memberId The user ID.
callback The success or failure callback. null cannot be returned.

Example

 TuyaHomeSdk.getDeviceShareInstance().getReceivedShareInfo(mRelationId, new ITuyaResultCallback<ShareReceivedUserDetailBean>() {
                @Override
                public void onSuccess(ShareReceivedUserDetailBean shareReceivedUserDetailBean) {}
                @Override
                public void onError(String errorCode, String errorMsg) {}
            });

Query a list of users who share a device

API description

void queryDevShareUserList(String devId, final ITuyaResultCallback<List<SharedUserInfoBean>> callback);

Parameters

Parameter Description
devId The device ID.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().queryDevShareUserList(mDevId, new ITuyaResultCallback<List<SharedUserInfoBean>>() {
        @Override
        public void onError(String errorCode, String errorMsg) {}
        @Override
        public void onSuccess(List<SharedUserInfoBean> shareUserBeen) {}
    });

Query the source of a shared device

API description

void queryShareDevFromInfo(String devId, final ITuyaResultCallback<SharedUserInfoBean> callback);

Parameters

Parameter Description
devId The device ID.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().queryShareDevFromInfo(devId, new ITuyaResultCallback<SharedUserInfoBean>() {
            @Override
            public void onSuccess(SharedUserInfoBean result) {
            }
            @Override
            public void onError(String errorCode, String errorMessage) {
            }
        });

Remove sharing mappings

Remove all invitees from an inviter

Removes all users who receive sharing invitations from a user denoted by memberId who initiates sharing invitations.

API description

void removeUserShare(long memberId, IResultCallback callback);

Parameters

Parameter Description
memberId The user ID.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().removeUserShare(memberId, new IResultCallback() {
    @Override
    public void onError(String code, String error) {
    }
    @Override
    public void onSuccess() {
    }
})

Remove all inviters from an invitee

Removes all users who initiate sharing invitations from a user denoted by memberId who receives sharing invitations.

API description

void removeReceivedUserShare(long memberId, IResultCallback callback);

Parameters

Parameter Description
memberId The ID of the user who receives the sharing invitations.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().removeReceivedUserShare(memberId, new IResultCallback() {
    @Override
    public void onError(String code, String error) {
    }
    @Override
    public void onSuccess() {
    }
})

Remove a shared device

API description

void disableDevShare(String devId, long memberId, IResultCallback callback);

Parameters

Parameter Description
devId The device ID.
memberId The user ID.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().disableDevShare (devId, memberId, new IResultCallback() {
    @Override
    public void onError(String code, String error) {
    }
    @Override
    public void onSuccess() {
    }
});

Remove a received shared device

API description

void removeReceivedDevShare(String devId, IResultCallback callback);

Parameters

Parameter Description
devId The device ID.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().removeReceivedDevShare(devId,new IResultCallback() {
    @Override
    public void onError(String code, String error) {}
    @Override
    public void onSuccess() {}
})

Modify remarks

Modify remarks of a user who initiates sharing invitations

API description

void renameShareNickname(long memberId, String name, IResultCallback callback);

Parameters

Parameter Description
memberId The user ID.
name The new remarks of the user who initiates the sharing invitations.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().renameShareNickname(mRelationId, inputText, new IResultCallback() {
                @Override
                public void onError(String s, String s1) {}
                @Override
                public void onSuccess() {}
            });

Modify remarks of a user who receives sharing invitations

API description

void renameReceivedShareNickname(long memberId, String name, IResultCallback callback);

Parameters

Parameter Description
memberId The home ID. You can call SharedUserInfoBean to get the value.
name The new remarks of the user who initiates the sharing invitations.
callback The success or failure callback. null cannot be returned.

Example

TuyaHomeSdk.getDeviceShareInstance().renameReceivedShareNickname(mRelationId, inputText, new IResultCallback() {
                @Override
                public void onError(String s, String s1) {}
                @Override
                public void onSuccess() {}
            });

Send sharing invitations

Initiate device sharing with another user

API description

void inviteShare(String devId, String userAccount, String countryCode, ITuyaResultCallback<Integer> callback);

Parameters

Parameter Description
countryCode The country code.
userAccount The target user account.
devId The device ID.
success The success callback.
failure The failure callback.

Example

    TuyaHomeSdk.getDeviceShareInstance().inviteShare(devId, userAccount, countryCode, new ITuyaResultCallback<Integer>() {
                @Override
                public void onSuccess(Integer result) {
                    
                }
    
                @Override
                public void onError(String errorCode, String errorMessage) {
    
                }
            });

Confirm a sharing invitation

API description

 void confirmShareInviteShare(int shareId, final IResultCallback callback);

Parameters

Parameter Description
shareId The ID of the sharing invitation. It is the integer value returned on success by the method inviteShare.
success The success callback.
failure The failure callback.

Example

 TuyaHomeSdk.getDeviceShareInstance().confirmShareInviteShare(shareId, new IResultCallback() {
            @Override
            public void onError(String code, String error) {
                
            }

            @Override
            public void onSuccess() {

            }
        });

Share devices with a group

Query a list of users who share devices by group ID

Note: The group ID appears on the device panel.

API description

void queryGroupSharedUserList(long groupId, ITuyaResultCallback<List<SharedUserInfoBean>> callback);

Parameters

Parameter Description
groupId The group ID.
success The success callback.
failure The failure callback.

Example

TuyaHomeSdk.getDeviceShareInstance().queryGroupSharedUserList(mGroupId, new ITuyaResultCallback<List<SharedUserInfoBean>>() {
            @Override
            public void onSuccess(List<SharedUserInfoBean> result) {
                
            }

            @Override
            public void onError(String errorCode, String errorMessage) {

            }
        });

Add a user to a sharing group

API description

void addShareUserForGroup(long homeId, String countryCode, String userAccount, long groupId, IResultCallback callback);

Parameters

Parameter Description
homeId The home ID.
countryCode The country code.
userAccount The target user account.
groupId The group ID.
success The success callback.
failure The failure callback.

Example

    TuyaHomeSdk.getDeviceShareInstance().addShareUserForGroup(homeId, countryCode, userAccount, groupId, new IResultCallback() {
            @Override
            public void onError(String code, String error) {
                
            }

            @Override
            public void onSuccess() {

            }
        });

Remove a user from a sharing group

API description

void removeGroupShare(long groupId, long memberId, IResultCallback callback);

Parameters

Parameter Description
memberId The member ID.
groupId The group ID.
success The success callback.
failure The failure callback.

Example

      TuyaHomeSdk.getDeviceShareInstance().removeGroupShare(groupId, memberId, new IResultCallback() {
            @Override
            public void onError(String code, String error) {

            }

            @Override
            public void onSuccess() {

            }
        });