T1 Dual Screen Communication Interface

                       Descriptions for the Key Classes (Docking Document for T1 Double Screen Communication Interface)

Including sunmi.ds

DSKernel class: SDK core class, which exposes the function to send data to second screen and initialize SDK

  •  newInstance(): DSKernel

Descriptions: instantiate the static function of DSKernel class.

  •  getDSDPackageName(): String

Descriptions: static function to obtain App package name of second screen receive data.

Return value: packageName, the second screen is responsible for receiving App package name of the data

  • init(Context context, IConnectionCallback stateCallback, StringvicePackageName): void

Descriptions: initialize SDK.

Parameters:

context: android context object.

stateCallback: callback of second screen’s connection status.

  •  isConnected():boolean

Descriptions: judge whether the double screen communication connection is smooth or not

Return value: isConn true is smooth, false is disconnected.

  • sendData(DataPacket pack): void

Parameters:

pack: object of DataPacket type, which has encapsulated the data to be sent.

  •  sendCMD(String recePackageName, String cmd, long fileId, ISendCallback callback): void

Descriptions: send CMD command package, you may specify the cache file id to be used.

Parameters:

recePackName: name of the receiving end package.

cmd: command. fileId: the cache file id to be used; if not available, transfer 0.

callback: send the result callback.

  • sendCMD(DataPacket dataPacket): void

Descriptions: send CMD command package, you may specify the cache file id to be used.

Parameters: dataPacket: CMD type data package.

  •  sendQuery(DataPacket mPack, QueryCallback callback): void

Descriptions: send data, used when the second screen sends the query data package.

For example: in the user protocol layer, main screen sends a query data package to the second screen, which indicates the query about second screen brightness. After the second screen has received it and obtained the brightness, it will then invoke sendResult(long queryId) function to send back a result data package carrying brightness to the main screen, and this Result data package’s queryId must be consistent with the taskId of Query data package. Only in this way can the main screen recognize that it’s the previous query result.

Note: when using QueryCallback to receive the result data package, the callback example registered via addReceiveCallback() will not be invoked.

Parameters:  pack: object of DataPacket type, which has encapsulated the data to be sent. callback query result callback 

  •  sendQuery(String recePackageName, String queryStr, ISendCallback, sendCallback, QueryCallback callback): void

Descriptions: send data, used when the second screen sends the query data package. For example: in the user protocol layer, main screen sends a query data package to the second screen, which indicates the query about second screen brightness. After the second screen has received it and obtained the brightness, it will then invoke sendResult(long queryId) function to send back a result data package carrying brightness to the main screen, and this Result data package’s queryId must be consistent with the taskId of Query data package. Only in this way can the main screen recognize that it’s the previous query result.

Note: when using QueryCallback to receive the result data package, the callback example registered via addReceiveCallback() will not be invoked.

Parameters: recePackageName: receiving end package name. queryStr: character string data to be carried

sendCallback: send the result callback    callback: query about the result callback

  •  sendResult(String recePackageName, String resultStr, long queryId, ISendCallback sendCallback): void

Descriptions: send Result data package. Parameters: recePackName: receiving end package name. resultStr: query result. queryId: taskId of Query data package. sendCallback: send result callback.

  •  sendFile(String recePackName, String filePath, ISendCallback callback): long

Descriptions: send file.

Parameters: recePackName: app package name received by the second screen. filePath: file path. callback: send the result callback.

Return value: taskId, maintain this task Id until receiving the callback that has been sent successfully. Then you can send command to the second screen and carry out the customization operation of the file. For example: the operations of displaying pictures, opening files, etc.

Note: after the file has been transmitted to the second screen, it will be cached and form mapping relation with the returned taskId. If you want to reuse this file for a long term, you need to maintain taskId permanently.

  •  sendFile(String recePackName, String msg, String filePath, ISendCallback callback): long

Descriptions: send data of one file + String type.    Parameters: recePackName: app package name received by the second screen.  msg: data of String type, for example: a character string of json format, a paragraph of text information, etc.  filePath: file path.  callback: send the result callback. 

Return value: taskId, maintain this task Id until receiving the callback that has been sent successfully. Then you can send command to the second screen and carry out the customization operation of the file. For example: the operations of displaying pictures, opening files, etc. 

Note: after the file has been transmitted to the second screen, it will be cached and form mapping relation with the returned taskId. If you want to reuse this file for a long term, you need to maintain taskId permanently.

  •  sendFilles(String recePackName, String msg, List files, ISendFilesCallback callback): long

Descriptions: send data of several files + String type.  Parameters: recePackName: app package name received by the second screen.  msg: data of String type, for example: a character string of json format, a paragraph of text information, etc.  files: file paths set.  Callback: send the result callback in terms of several files.

Return value: taskId, maintain this task Id until receiving the callback that has been sent successfully. Then you can send command to the second screen and carry out the customization operation of the file. For example: the operations of displaying pictures, opening files, etc.

Note: after the file has been transmitted to the second screen, it will be cached and form mapping relation with the returned taskId. If you want to reuse this file for a long term, you need to maintain taskId permanently.

  •  checkFileExist(long fileId, final ICheckFileCallback callback): void

Descriptions: check whether the file corresponding to fileId exists on the second screen or not

Parameters: fileId:file Id.  callback: check the result callback

  •  addConnCallback(IConnectionCallback callback): void

Descriptions: register a callback to monitor connection, you can register several ones.

Parameters: stateCallback: callback the status of connection with the second screen.

  •  removeConnCallback(IConnectionCallback callback): void

Descriptions: remove the callback to monitor connection.

Parameters: stateCallback: callback the status of connection with the second screen.

  •  checkConnection(): void

Descriptions: detect the status of connection with the second screen. If there is a result, the registered IConnectionCallback will be called back.

  •  addReceiveCallback(IReceiveCallback receiveCallback): void

Descriptions: register the callback of data receiving, you can register several ones.

Parameters: receiveCallback: the receiving end is used in the callback interface that receives the sending end data.

  • removeReceiveCallback(IReceiveCallback receiveCallback): void

Descriptions: remove the data receiving callback.

Parameters: receiveCallback: callback example to be logged out.

FilesManager class: maintain permanently the files received by the cache, cache DSFile, DSFiles taking taskId that sends file task as key.

  •  getFile(Long taskId): DSFile descriptions: obtain the file according to task ID.  Parameters: taskId: task ID corresponding to the file.

  •  getFile(Long taskId): DSFile descriptions: obtain several files according to task ID.  Parameters: taskId: task ID corresponding to the file.

sunmi.ds.callback package

IReceiveCallback class: the callback interface during the data receiving.

  • onReceiveData(DSData data): void   Descriptions: callback upon receiving the data.  Parameters: data: data that have been received

data that have been received

  • onReceiveFile(DSFile file): void   Descriptions: callback upon receiving single file.  Parameters: file: filethat has been received

  • onReceiveFiles(DSFiles files): void   Descriptions: callback upon receiving data of >=one file + a paragraph of String type.  Parameters: files: the files that have been received + String data

 onReceiveCMD(DSData cmd): void   Descriptions: callback upon receiving data of CMD type.  

Parameters: cmd: data of CMD type that have been receivedreceiving the query result data package.

QueryCallback class: callback upon receiving the query result data package.

  • onReceiveData(DSData data): void   Descriptions: callback upon receiving the result data package.Parameters: data: data that have been received

IConnectionCallback class: callback interface in double screen communication connection status, all the callback functions run in child thread.

  • onDisConnect(): void   Descriptions: callback when disconnected.

  • onDisConnect(ConnState state): void   Descriptions: callback when the connection status is updated. 

The connection statuses are divided into 3 types: 1. normal link with local service; 2. normal connection with second screen service (in this status, it’s OK to send data to the second screen); 3. normal connection with second screen App.   Parameters: state: connection status

ICheckFileCallback class: check the file result callback interface.

  • onCheckFail(): void   Descriptions: check fails (communication fails).

  • onResult(Boolean exist): Boolean  Descriptions: check fails (communication fails).

Parameters: exist: true indicates existence, false indicates non-existence.

IConnectionCallback class: callback interface in double screen communication connection status, all the callback functions run in child thread.

  • onDisConnect(): void   Descriptions: callback when disconnected.

  • onDisConnect(ConnState state): void   Descriptions: callback when the connection status is updated. 

The connection statuses are divided into 3 types: 1. normal link with local service; 2. normal connection with second screen service (in this status, it’s OK to send data to the second screen); 3. normal connection with second screen App.   Parameters: state: connection status

ISendCallback class: callback interface to send String data or single file, all the callback functions run in child thread.

  • onSendSuccess(long taskId): void  Descriptions: callback upon successful sending. taskId: task Id,corresponding to the data or file to be sent.

  • onSendFail(int errorId, String errorInfo): void  Descriptions: callback upon failure in sending.Parameters: errorId: error identification code. errorInfo: error descriptions.

  • onSendProcess(long totle, long sended): void   Descriptions: callback of sending progress.  Parameters: totle: total size of the data, unit: byte.  sended: size of the data that have already been sent, unit: byte.

ISendFilesCallback class: callback interface to send >=one file+String data, all the callback functions run in child thread.
  • onAllSendSuccess(long fileId): void  Descriptions: callback upon the successful sending of several files.fileId: task Id is also the corresponding fielId cached in the second screen file.

  • onSendSuccess(String path, long taskId): void  Descriptions: callback upon the successful sending of one certain file. taskId: task Id, the taskId of several files to be sent are the same since they belong to the same task.

  • onSendFail(int errorId, String errorInfo): void  Descriptions: callback upon the failure in sending Stringdata, String data will not continue to send files after it fails to be sent.   Parameters: errorId: error identification code. errorInfo: error descriptions.

  • onSendFileFaile(String path, int errorId, String errorInfo): void  Descriptions: callback upon the failure in sending one certain file.  Parameters: path: the file path corresponding to sending failure. errorId: error identification code. errorInfo: error descriptions.

  • onSendProcess(String path, long totle, long sended): void  Descriptions: callback of the progress of sending one certain file.   Parameters: path: the corresponding file path. totle: total size of the data, unit: byte.  sended: size of the data that have already been sent, unit: byte

sunmi.ds.data package

DataPacket class: it has been encapsulated with sending data and sending callback, and it’s a parameter entity class required by invoking sendData(DataPacket pack) function of DSKernel class.

DataPacket.Builder class: DataPacket’s builder class.

  • Builder(DSData.DataType dataType) descriptions: constructor function.  Parameters: datatype: data type to be built.

  • recPackName(String recPackName): Builder descriptions: name of the App package to be specified to receive data.  Parameters: recPackName: name of the App package to receive data. Return value: Builder example

  •  data(String data): Builder descriptions: specify the data to be sent.   Parameters: data: String data to be 

sent.  Return value: Builder example

  • taskId(long taskId): Builder descriptions: specify the task Id, it will be automatically generated if not specified.  Parameters: taskId: task Id.   Return value: Builder example

  • fileId(long fileId): Builder descriptions: specify the cache file Id.  Parameters: fileId: cache file Id.   Return value: Builder example

  • queryId(long queryId): Builder descriptions: specify Id of Query data package.  Parameters: fileId: Id of Query data package.  Return value: Builder example

  • isReport(Boolean isReport): Builder descriptions: specify whether result callback is required or not. Parameters: isReport: whether result callback is required or not.  Return value: Builder example.

  •  addCallback(ISendCallback callback): Builder descriptions: example of setting sending result callback. Parameters: callback: example of sending result callback.  Return value: Builder example

  •  build(): DataPacket descriptions: example of building one DataPacket.  Return value: DataPacket example

DSData class: data encapsulation of double screen communication.

  •  sender: String descriptions: app package name at the sending end.

  •  taskId: long descriptions: task Id.

  •  fileId: long descriptions: cache file Id.

  •  queryId: long descriptions: task Id of Query data package.

  •  dataType: DataType descriptions: data type.

  •  data: String descriptions: data to be sent.

DSData.DataType enumeration class: data type describes the encapsulation.

  •  DATA: DataType descriptions: indicating data.

  •  FILE: DataType descriptions: indicating file.

  •  CMD: DataType descriptions: indicating command.

  •  typeCode: int descriptions: type code.

DSFile class: file class to be received at the receiving end.

  •  sender: String descriptions: name of app package at the sending end.

  •  path: String descriptions: file path to be received.

  •  taskId: long descriptions: task Id.

DSFiles class: multiple files class to be received at the receiving end.

  •  filesDescribe: FilesDescribe descriptions: String data and file quantity to be received has been encapsulated.
  •  sender: String descriptions: name of app package at the sending end.
  •  files: List descriptions: file path set to be received.
  •  taskId: long descriptions: task Id.

FilesDescribe class: String data and file quantity to be received has been encapsulated.

  •  msg: String descriptions: String data to be received.
  •  fileCount: int descriptions: file quantity.