This document is deprecated, please go to Tuya Developer Documentation Center to view the latest version: Tuya Smart Doc - Android SDK

1. Cloud Storage

Tuya IoT provides cloud storage service for smart camera, which can upload the video recorded by the device to Tuya cloud.

1.1. Flow chart

Request the cloud storage service status first. If the cloud storage service is not activated or has expired and the cloud video has been completely deleted (after the cloud storage service expires, the uploaded cloud video will be retained for some days), you need to first purchase cloud storage services. If the cloud storage service is in the validity period, first request the dates of the cloud storage video, and then request the relevant data of the specified date, including cloud storage events, timeline data, authentication information, etc. After that, you can choose a cloud storage event or a point in time to start playing cloud video.

1.2. Cloud service

Cloud service purchase biz bundle provides H5 pages and order display functions for cloud storage purchases.

1.3. Cloud video

1.3.1. Cloud storage data

CameraCloudSDK is an entity object called by the API interface of cloud storage ATOP, and provides API methods related to obtaining cloud storage purchase and time data.

Get cloud storage current status value (with or without purchase, etc.)

void getCameraCloudInfo(DeviceBean deviceBean, ICloudCacheManagerCallback callback)

Parameter

Parameter Description
deviceBean device info
callback Callback

Example

cameraCloudSDK.getCameraCloudInfo(TuyaHomeSdk.getDataInstance().getDeviceBean(devId), CameraCloudStorageActivity.this);
public void getCloudMediaCount(String devId, String timeZone, ICloudCacheManagerCallback callback)

Parameter

Parameter Description
devId device Id
timeZone time Zone
callback Callback

Example

cameraCloudSDK.getCloudMediaCount(devId, TimeZone.getDefault().getID(), CameraCloudStorageActivity.this);

Get time slice at specified time

public void getTimeLineInfoByTimeSlice(String devId, String timeGT, String timeLT, ICloudCacheManagerCallback callback)

Parameter

Parameter Description
devId device Id
timeGT Start time (13-bit timestamp)
timeLT End Time
callback Callback

Example

getTimeLineInfoByTimeSlice(devId, String.valueOf(dayBean.getCurrentStartDayTime()), String.valueOf(dayBean.getCurrentDayEndTime()));

Get the corresponding motion detection data according to the beginning and end of the time segment

public void getMotionDetectionByTimeSlice(String devId, String timeGT, String timeLT, int offset, int limit, ICloudCacheManagerCallback callback)

Parameter

Parameter Description
devId device Id
timeGT Start time (13-bit timestamp)
timeLT End Time
offset Page number, default 0
limit Number of pulls at a time, default -1, which means all data
callback callback

Example

cameraCloudSDK.getMotionDetectionByTimeSlice(devId, timeGT, timeLT, offset, limit, this);

The real-time screenshots carried in the cloud storage event are encrypted and need to be displayed through the encrypted image component DecryptImageView. For details, refer to the Encrypted Image chapter.

Cloud storage purchase address interface

No longer in maintenance, please refer to cloud storage service package.

public void buyCloudStorage(Context mContext, DeviceBean deviceBean, String homeId, ICloudManagerCallback callback) {
  CameraCloudManager.getInstance().getCloudStorageUrl(mContext, deviceBean, homeId);
}

Parameter

Parameter Description
mContext /
deviceBean device Info
homeId home Id
callback callback

Example

cameraCloudSDK.buyCloudStorage(CameraCloudStorageActivity.this,
                               TuyaHomeSdk.getDataInstance().getDeviceBean(devId),
                               String.valueOf(FamilyManager.getInstance().getCurrentHomeId()), new ICloudManagerCallback() {
                                 @Override
                                 public void onError(int i) {

                                 }

                                 @Override
                                 public void onSuccess(Object o) {
                                   String uri = (String) o;
                                   Intent intent = new Intent(CameraCloudStorageActivity.this, WebViewActivity.class);
                                   intent.putExtra("Uri",uri);
                                   startActivity(intent);
                                 }
                               });

Destroy

public void onDestroy()

Example

if (null != cameraCloudSDK) {
  cameraCloudSDK.onDestroy();
}

ICloudCacheManagerCallback

Parameter

Callback method after calling SDK

public interface ICloudCacheManagerCallback {

    /**
     * return date with cloud storage data
     *
     * @param cloudDayBeanList: Cloud storage date List
     */
    void getCloudDayList(List<CloudDayBean> cloudDayBeanList);

    /**
     * return cloud storage encryKey
     *
     * @param encryKey: Cloud storage key
     */
    void getCloudSecret(String encryKey);

    /**
     * return authorityJson
     *
     * @param authorityJson: Cloud storage key
     */
    void getAuthorityGet(String authorityJson);

    /**
     * return data queried by cloud storage based on a certain time period.
     *
     * @param timePieceBeans: Time-slice data list
     */
    void getTimePieceInfoByTimeSlice(List<TimePieceBean> timePieceBeans);

    /**
     * return data from cloud storage motion detection queries based on a certain time period.
     *
     * @param timeRangeBeans: Motion detection time segment data list
     */
    void getMotionDetectionByTimeSlice(List<TimeRangeBean> timeRangeBeans);

    /**
     * error code
     *
     * @param errorCode
     */
    void onError(int errorCode);

    /**
     * return cloud storage status
     *
     * @param code: code value, refer to the status code at the bottom of the article.
     */
    void getCloudStatusSuccess(int code);

    /**
     * return cloud storage configuration information, need to pass in SDK verification
     *
     * @param config: Configuration information data
     */
    void getCloudConfigDataTags(String config);
}

Status value

Status value Description
10001 Not Opened
10002 Service opened, no data
10003 Service is available, data is available
10004 Service expired with data
10005 Service expired, no data

Error code

error code Description
10100 Get SECRET failed
10101 Failed to get AUTH
10110 Other exceptions
10010 Failed to obtain authentication information
10011 Failed to get time slice (authentication information) for a certain day

1.3.2. Cloud video playback

ITYCloudCamera provides API interfaces related to cloud storage playback.

Initialize and create device

void createCloudDevice(String cachePath, String devId)

Parameter

Parameter Description
cachePath Cache path
devId device Id

Example

cloudCamera.createCloudDevice(cachePath, devId);

Register for Cloud camera listening

void registorOnP2PCameraListener(OnP2PCameraListener listener);

Parameter

Parameter Description
listener Callback

Example

cloudCamera.registorOnP2PCameraListener(this);

Unregister Cloud Camera listening

void removeOnP2PCameraListener();

Example

cloudCamera.removeOnP2PCameraListener(this);

Binder video View

void generateCloudCameraView(IRegistorIOTCListener view);

Parameter

Parameter Description
view Video view

Example

cloudCamera.generateCloudCameraView(mVideoView);

Configure cloud storage data tags (requires configuration before starting to play cloud storage).

int configCloudDataTagsV1(String jsonStr, OperationDelegateCallBack callBack);

Parameter

Parameter Description
jsonStr Configure cloud storage data tags
callBack Callback

Example

cloudCamera.configCloudDataTagsV1(config, new OperationDelegateCallBack() {

  @Override
  public void onSuccess(int i, int i1, String s) {
    if (timePieceBeans.size() > 0) {
      int startTime = timePieceBeans.get(0).getStartTime();
      playCloudDataWithStartTime(startTime, (int) (getTodayEnd(startTime * 1000L) / 1000) - 1, true);
    }
  }

  @Override
  public void onFailure(int i, int i1, int i2) {

  }
});

Cloud storage playing

void playCloudDataWithStartTime(long mStartTime, long mEndTime, boolean isEvent, String jsonAuthParams, String encryptKey, OperationCallBack callback, OperationCallBack playFinishedCallBack);

Parameter Description

Parameter Description
mStartTime Starting time
mEndTime End time, usually the end time of the day
isEvent Whether to detect events, default false
jsonAuthParams Check data
encryptKey Secret key
callBack play callback
playFinishedCallBack Play finish callback

Sample Code

cloudCamera.playCloudDataWithStartTime(startTime, endTime, isEvent,
                                       mAuthorityJson, mEncryptKey,
                                       new OperationCallBack() {
                                         @Override
                                         public void onSuccess(int sessionId, int requestId, String data, Object camera) {

                                         }

                                         @Override
                                         public void onFailure(int sessionId, int requestId, int errCode, Object camera) {

                                         }
                                       }, new OperationCallBack() {
                                         @Override
                                         public void onSuccess(int sessionId, int requestId, String data, Object camera) {

                                         }

                                         @Override
                                         public void onFailure(int sessionId, int requestId, int errCode, Object camera) {
                                         }
                                       });

Pause playing

int pausePlayCloudVideo(OperationDelegateCallBack callBack);

Parameter

Parameter Description
callBack call back

Example

cloudCamera.pausePlayCloudVideo(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {

  }
});

Resume playing

int resumePlayCloudVideo(OperationDelegateCallBack callBack);

Parameter

Parameter Description
callBack call back

Example

cloudCamera.resumePlayCloudVideo(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {

  }
});

Stop playing

int stopPlayCloudVideo(OperationDelegateCallBack callBack);

Parameter

Parameter Description
callBack call back

Example

cloudCamera.stopPlayCloudVideo(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {

  }
});

Declaration

download cloud videos.

void startCloudDataDownload(long startTime, long stopTime, String jsonAuthParams, String encryptKey, String folderPath, String mp4FileName,
                                OperationCallBack callback, ProgressCallBack progressCallBack, OperationCallBack finishedCallBack);

Parameters

Parameter Description
startTime start time, unit second
stopTime end time, unit second
jsonAuthParams check data
encryptKey secret key
folderPath file path to save video
mp4FileName file name
callback operation callback
progressCallBack download progress callback
finishedCallBack download finish callback

Declaration

stop download cloud video.

void stopCloudDataDownload(OperationCallBack callBack);

Parameters

Parameter Description
callBack operation callback

Get sound status

int getCloudMute();

Example

cloudCamera.getCloudMute()

Set sound status

void setCloudMute(final int mute, OperationDelegateCallBack callBack);

Parameter

Parameter Description
mute is mute
callBack call back

Example

cloudCamera.setCloudMute(mute, new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    soundState = Integer.valueOf(data);
  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {
  }
});

snapshot

int snapshot(String absoluteFilePath, OperationDelegateCallBack callBack);

Parameter

Parameter Description
absoluteFilePath file path
callBack call back

Example

cloudCamera.snapshot(IPCCameraUtils.recordSnapshotPath(devId), new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    Toast.makeText(CameraCloudStorageActivity.this, "snapshot success", Toast.LENGTH_SHORT).show();
  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {
  }
});

1.3.3. start Recording

int startRecordLocalMp4(String folderPath, String fileName, OperationDelegateCallBack callBack);

Parameter

Parameter Description
folderPath folder path
fileName file name
callBack Call back

Example

cloudCamera.startRecordLocalMp4(IPCCameraUtils.recordPath(devId), String.valueOf(System.currentTimeMillis()), new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    Toast.makeText(CameraCloudStorageActivity.this, "record start success", Toast.LENGTH_SHORT).show();
  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {
  }
});

Stop recording

int stopRecordLocalMp4(OperationDelegateCallBack callBack);

Parameter

Parameter Description
callBack call back

Example

cloudCamera.stopRecordLocalMp4(new OperationDelegateCallBack() {
  @Override
  public void onSuccess(int sessionId, int requestId, String data) {
    Toast.makeText(CameraCloudStorageActivity.this, "record end success", Toast.LENGTH_SHORT).show();
  }

  @Override
  public void onFailure(int sessionId, int requestId, int errCode) {
  }
});

1.3.4. Deinit

void deinitCloudCamera();

Example

cloudCamera.deinitCloudCamera();

results matching ""

    No results matching ""