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:
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()
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.
|
callback | IThingResultCallback<Boolean> |
The success callback.
|
Sample call
manager.isSupportDeviceShare(resId, resType, new IThingResultCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
}
@Override
public void onError(String errorCode, String errorMessage) {
}
});
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.
|
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) {
}
});
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.
|
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;
}
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.
|
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() {
}
});
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.
|
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() {
}
});
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.
|
memberId | Long | The member ID. |
mode | int | The effective mode.
|
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) {
}
});
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) {
}
});
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) {
}
});
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.
|
spaceId | longlong | The home ID of the device. |
shareType | int | The sharing channel.
|
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) {
}
}
});
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.
|
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) {
}
});
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) {
}
});
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() {
}
});
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.
|
callback | IThingResultCallback<String> |
The callback. The sharer name is returned for a successful callback. |
name
exists, name
is returned as a priority.name
does not exist, mobile
is returned.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) {
}
});
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.
|
callback | IResultCallback() | The callback. |
Sample call
manager.removeReceivedShare(resId, resType, new IResultCallback() {
@Override
public void onError(String code, String error) {
}
@Override
public void onSuccess() {
}
});
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) {
}
});
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) {
}
});
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() {
}
});
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() {
}
});
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback