Device Sharing

Last Updated on : 2024-11-12 07:46:09download

Device managers can share a device with others (known as the receivers). The receivers can use the device after accepting the share invitation.

The main features include:

  • Device managers can share a device or group and query or removes receivers.
  • Receivers can accept device share invitations and query or remove sharers.

Overview

The device sharing SDK implements APIs in the ThingDeviceShareManager and IDeviceShareManager classes. This topic describes the parameters required for each API.

API description

API Description
isSupportDeviceShare Determines whether the device or group can be shared.
addTimer Adds a timer for the device or group.
editTimer Updates the timer for the device or group.
deleteTimer Deletes the timer for the device or group.
updateTimerStatus Updates the timer status.

Class instantiation example

IDeviceShareManager mShareManager = DeviceBusinessDataManager.getInstance().getDeviceShareManager();
ThingDeviceShareManager manager = new ThingDeviceShareManager()

APIs related to sharers

Determine whether a device or group can be shared

API description

fun isSupportDeviceShare(String resId, int resType, IThingResultCallback<Boolean> callback);

Parameters

Parameter Type Description
resId String The ID of the device or group.
resType int The type of the resource to be shared.
  • 1: device
  • 2: group
callback IThingResultCallback<Boolean> The success callback.
  • true: The device or group can be shared.
  • false: The device or group cannot be shared.

Sample call

manager.isSupportDeviceShare(resId, resType, new IThingResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {

            }

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

            }
        });

Query the remaining share times of the device or group

API description

fun querySharedCount(resId: String, shareType: int, listener: Business.ResultListener<Long>)

Parameters

Parameter Type Description
resId string The ID of the device or group.
resType int The type of the resource to be shared.
  • 1: device
  • 2: group
listener Business.ResultListener<Long> The callback. The remaining share times is returned for a successful callback.

Sample call

IDeviceShareManager mShareManager  = DeviceBusinessDataManager.getInstance().getDeviceShareManager();

mShareManager.querySharedCount(resId, shareType, new ResultListener<Long>() {
            @Override
            public void onFailure(BusinessResponse bizResponse, Long bizResult, String apiName) {

            }

            @Override
            public void onSuccess(BusinessResponse bizResponse, Long bizResult, String apiName) {

            }
        });

Share a device or group with a specified user

API description

fun shareToUser(String resId, int resType,Long spaceId,String userAccount,IThingResultCallback<SharedUserInfoBean> callback);

Parameters

Parameter Type Description
resId String The ID of the device or group.
resType int The type of the resource to be shared.
  • 1: device
  • 2: group
userAccount String The account of the receiver.
spaceId Long The home ID of the device.
callback IThingResultCallback<SharedUserInfoBean> The callback. The sharing result is returned.

Sample call

manager.shareToUser(resId, resType, spaceId, userAccount, new IThingResultCallback<SharedUserInfoBean>() {
            @Override
            public void onSuccess(SharedUserInfoBean result) {

            }

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

            }
        });

SharedUserInfoBean data structure

public class SharedUserInfoBean {
    private long memeberId;
    private String remarkName;
    private String userName;
    private String iconUrl;
    private String mobile;
    private long homeId;
    private String headPic;
    private String userAccount;
}

Query current receivers of a shared device or group

API description

fun getReceivers(String resId, int resType, int page, int pageSize, IThingResultCallback<List<ShareMember>> callback);

Parameters

Parameter Type Description
resId String The ID of the device or group.
resType int The type of the resource to be shared.
  • 1: device
  • 2: group
page int The page number.
pageSize int The page size.
callback IThingResultCallback<List<ShareMember>> The callback. ShareMember is returned for a successful callback.

ShareMember data structure

public class ShareMember {
    private Long memberId;
    private String nickName;
    private String userName;
    private String iconUrl;
    private int shareMode;
    private Long endTime;
    private String uid;
}

Sample call

ThingDeviceShareManager manager = new ThingDeviceShareManager();
        manager.getReceivers(resId,resType, page, pageSize, new IThingResultCallback<List<ShareMember>> {
            @Override
            public void onError(String code, String error) {

            }

            @Override
            public void onSuccess() {

            }
        });

Remove current receivers of a shared device or group

API description

fun removeReceiver(Long memberId, String resId, int resType, IResultCallback callback);

Parameters

Parameter Type Description
memberId Long The user ID.
resId String The ID of the device or group.
resType int The type of the resource to be shared.
  • 1: device
  • 2: group
callback IResultCallback The callback.

Sample call

ThingDeviceShareManager manager = new ThingDeviceShareManager();
        manager.removeReceiver(memberId,resId,resType, new IResultCallback() {
            @Override
            public void onError(String code, String error) {

            }

            @Override
            public void onSuccess() {

            }
        });

Update the expiration time of sharing

API description

fun updateSharedDeadline(relationId: Long, resId: String, shareType: Int, shareMode:Int, shareEndTime: Long, listener: Business.ResultListener<Boolean>)

Parameters

Parameter Type Description
resId String The ID of the device or group.
resType int The type of the resource to be shared.
  • 1: device
  • 2: group
memberId Long The member ID.
mode int The effective mode.
  • 0: valid permanently
  • 1: valid for a period of time
endTime Long The end timestamp, in milliseconds.
callback ResultListener<Boolean> The callback.

Sample call

IDeviceShareManager mShareManager  = DeviceBusinessDataManager.getInstance().getDeviceShareManager();

mShareManager.updateSharedDeadline(memberId, resId, resType, mode, endTime, new ResultListener<Boolean>() {
            @Override
            public void onFailure(BusinessResponse bizResponse, Boolean bizResult, String apiName) {

            }

            @Override
            public void onSuccess(BusinessResponse bizResponse, Boolean bizResult, String apiName) {

            }
        });

Query recently shared users

API description

fun getRelationMembers(IThingResultCallback<List<ShareMember>> callback);

Parameters

Parameter Type Description
callback IThingResultCallback<List<ShareMember>> The callback. List<ShareMember> is returned for a successful callback.

Sample call

ThingDeviceShareManager manager = new ThingDeviceShareManager();
manager.getRelationMembers(new IThingResultCallback<List<ShareMember>>() {
            @Override
            public void onSuccess(List<ShareMember> result) {

            }

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

            }
        });

Remove a recently shared user

API description

fun deleteSharedContact(hideUserId: String, listener: Business.ResultListener<kotlin.Boolean>)

Parameters

Parameter Type Description
uid String The ID of the member to be removed.
callback ResultListener<Boolean>() The callback.

Sample call

mShareManager.deleteSharedContact(uid, new ResultListener<Boolean>() {
            @Override
            public void onFailure(BusinessResponse bizResponse, Boolean bizResult, String apiName) {

            }

            @Override
            public void onSuccess(BusinessResponse bizResponse, Boolean bizResult, String apiName) {

            }
        });

Create a short share URL

API description

fun createShareLink(resId: String, shareType: Int, groupId: Long, shareSource: Int, shareCount: Int, listener: Business.ResultListener<ShareDeviceLinkResultBean>)

Parameters

Parameter Type Description
resId string The ID of the device or group.
resType int The type of the resource to be shared.
  • 1: device
  • 2: group
spaceId longlong The home ID of the device.
shareType int The sharing channel.
  • 0: Accounts
  • 1: Tencent QQ
  • 2: WeChat
  • 3: Message
  • 4: Email
  • 5: Copy
  • 6: More
  • 7: Contact
shareCount int The number of times the device or group is shared through the short URL.
callback ResultListener<ShareDeviceLinkResultBean> The callback. The sharing information is returned for a successful callback.

Sample call

mShareManager.createShareLink(resId, resType, spaceId, shareType, shareCount, new ResultListener<ShareDeviceLinkResultBean>() {
            @Override
            public void onFailure(BusinessResponse businessResponse, ShareDeviceLinkResultBean shareDeviceLinkBean, String s) {
                if (callback ! = null) {

                }
            }

            @Override
            public void onSuccess(BusinessResponse businessResponse, ShareDeviceLinkResultBean shareDeviceLinkBean, String s) {
                if (callback ! = null) {

                }
            }
        });

APIs related to receivers

Check short URL validity

API description

fun parseShortLinkAvailability(String code,IThingResultCallback<Boolean> callback);

Parameters

Parameter Type Description
code string The short URL code.
callback IThingResultCallback<Boolean> The success callback.
  • true: valid
  • false: invalid

Sample call

private ThingDeviceShareManager manager = new ThingDeviceShareManager();
manager.parseShortLinkAvailability(code, new IThingResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {

            }

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

            }
        });

Get the result of the short URL code

API description

fun parseSharedDeviceLinkResult(shortCode: String, listener: Business.ResultListener<ShareShortLinkResult>):

Parameters

Parameter Type Description
code string The short URL code.
Callback ResultListener<ShareShortLinkResult> The callback. ShareShortLinkResult is returned for a successful callback.

Sample call

mShareManager.parseSharedDeviceLinkResult(shortCode, new ResultListener<ShareShortLinkResult>() {
            @Override
            public void onFailure(BusinessResponse bizResponse, ShareShortLinkResult bizResult, String apiName) {

            }

            @Override
            public void onSuccess(BusinessResponse bizResponse, ShareShortLinkResult bizResult, String apiName) {

            }
        });

Accept a share invitation

API description

fun acceptShare(String code,IResultCallback callback);

Parameters

Parameter Type Description
code string The short URL code.
callback IResultCallback() The callback.

Sample call

manager.acceptShare(code, new IResultCallback() {
            @Override
            public void onError(String code, String error) {

            }

            @Override
            public void onSuccess() {

            }
        });

View the name of a sharer

API description

fun getSharerName(String resId, int resType,IThingResultCallback<String> callback);

Parameters

Parameter Type Description
resId string The ID of the device or group.
resType int The type of the resource to be shared.
  • 1: device
  • 2: group
callback IThingResultCallback<String> The callback. The sharer name is returned for a successful callback.
  • If name exists, name is returned as a priority.
  • If name does not exist, mobile is returned.
  • If neither name nor mobile exists, email is returned.

Both mobile and email have been masked.

Sample call

manager.getSharerName(resId, resType, new IThingResultCallback<String>() {
            @Override
            public void onSuccess(String result) {

            }

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

            }
        });

Remove a shared device or group

API description

fun removeReceivedShare(String resId, int resType,IResultCallback callback);

Parameters

Parameter Type Description
resId string The ID of the device or group.
resType int The type of the resource to be shared.
  • 1: device
  • 2: group
callback IResultCallback() The callback.

Sample call

manager.removeReceivedShare(resId, resType, new IResultCallback() {
            @Override
            public void onError(String code, String error) {

            }

            @Override
            public void onSuccess() {

            }
        });

View the sharer list

API description

fun getShareReceivedUserList(IThingResultCallback<List<SharedUserInfoBean>> callback);

Parameters

Parameter Type Description
callback IThingResultCallback<List<SharedUserInfoBean>> The callback. SharedUserInfoBean is returned for a successful callback.

SharedUserInfoBean data structure

public class SharedUserInfoBean {
    private long memeberId;
    private String remarkName;
    private String userName;
    private String iconUrl;
    private String mobile;
    private long homeId;
    private String headPic;
    private String userAccount;
}

Sample call

manager.getShareReceivedUserList(new IThingResultCallback<List<SharedUserInfoBean>>() {
            @Override
            public void onSuccess(List<SharedUserInfoBean> result) {

            }

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

            }
        });

Query sharer information and shared devices

API description

fun getSharerInfoDetail(Long memberId,IThingResultCallback<ShareReceivedUserDetailBean> callback);

Parameters

Parameter Type Description
memberId long The member ID.
callback IThingResultCallback<ShareReceivedUserDetailBean> The callback. ShareReceivedUserDetailBean is returned for a successful callback.

ShareReceivedUserDetailBean data structure

public class ShareReceivedUserDetailBean {
    private String mobile;
    private List<DeviceShareBean> devices;
    private String remarkName;
    private String nameWithoutRemark;
}

Sample call

manager.getSharerInfoDetail(memberId, new IThingResultCallback<ShareReceivedUserDetailBean>() {
            @Override
            public void onSuccess(ShareReceivedUserDetailBean result) {

            }

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

            }
        });

Remove a sharer and shared devices

API description

fun removeReceivedUserShare(Long memberId,IResultCallback callback);

Parameters

Parameter Type Description
memberId long The member ID.
callback IResultCallback() The callback.

Sample call

manager.removeReceivedUserShare(memberId, new IResultCallback() {
            @Override
            public void onError(String code, String error) {

            }

            @Override
            public void onSuccess() {

            }
        });

Update the nickname of a sharer

API description

fun renameReceivedShareNickname(Long memberId,String name,IResultCallback callback);

Parameters

Parameter Type Description
memberId long The member ID.
name String The new nickname.
callback IResultCallback() The callback.

Sample call

manager.renameReceivedShareNickname(memberId, name, new IResultCallback() {
            @Override
            public void onError(String code, String error) {

            }

            @Override
            public void onSuccess() {

            }
        });