Device Sharing

Last Updated on : 2024-06-18 01:40:38download

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
IThingHomeDeviceShare 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 IThingResultCallback<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

ThingHomeSdk.getDeviceShareInstance().addShare(homeId, countryCode, userAccount,
                shareIdBean, autoSharing, new IThingResultCallback<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

ThingHomeSdk.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, IThingResultCallback<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

ThingHomeSdk.getDeviceShareInstance().addShareWithHomeId(homeId, countryCode,
                userAccount, devsIdList, new IThingResultCallback<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 IThingResultCallback<List<SharedUserInfoBean>> callback);

Parameters

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

Example

ThingHomeSdk.getDeviceShareInstance().queryUserShareList(homeId, new IThingResultCallback<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 IThingResultCallback<List<SharedUserInfoBean>> callback);

Parameters

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

Example

ThingHomeSdk.getDeviceShareInstance().queryShareReceivedUserList(new IThingResultCallback<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 IThingResultCallback<ShareSentUserDetailBean> callback);

Parameters

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

Example

ThingHomeSdk.getDeviceShareInstance().getUserShareInfo(mRelationId, new IThingResultCallback<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 IThingResultCallback<ShareReceivedUserDetailBean> callback);

Parameters

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

Example

 ThingHomeSdk.getDeviceShareInstance().getReceivedShareInfo(mRelationId, new IThingResultCallback<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 IThingResultCallback<List<SharedUserInfoBean>> callback);

Parameters

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

Example

ThingHomeSdk.getDeviceShareInstance().queryDevShareUserList(mDevId, new IThingResultCallback<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 IThingResultCallback<SharedUserInfoBean> callback);

Parameters

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

Example

ThingHomeSdk.getDeviceShareInstance().queryShareDevFromInfo(devId, new IThingResultCallback<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

ThingHomeSdk.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

ThingHomeSdk.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

ThingHomeSdk.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

ThingHomeSdk.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

ThingHomeSdk.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

ThingHomeSdk.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, IThingResultCallback<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

    ThingHomeSdk.getDeviceShareInstance().inviteShare(devId, userAccount, countryCode, new IThingResultCallback<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

 ThingHomeSdk.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, IThingResultCallback<List<SharedUserInfoBean>> callback);

Parameters

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

Example

ThingHomeSdk.getDeviceShareInstance().queryGroupSharedUserList(mGroupId, new IThingResultCallback<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

    ThingHomeSdk.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

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

            }

            @Override
            public void onSuccess() {

            }
        });