目录

Development for the Receiving Device

Scenario Design

For details, please refer to Scenario Design for the Receiving Device.

Development Process

Add the following code to the on-device user process to integrate the capabilities into the receiving device:
int main(int argc, char* argv[])
{
    signal(SIGINT, Exit);
    if (InitShareKit(NULL) != 0) {
        goto done;
    }
    ShareRecvHandle recvHandler;
    memset(&recvHandler, 0, sizeof(ShareRecvHandle));
    recvHandler.statusCb = SharekitStatusChangeCbFunc;
    recvHandler.previewCb = RequestFileTrans;
    recvHandler.finishCb = FileTransferResult;
    if (StartShareService(RECEIVER, &recvHandler) != 0) {
        goto done;
    }
    StopShareService();
    UninitShareKit();
    sleep(1);
    printf("main exit. \n");
    return 0;
}

[h2]Initializing Share Engine

Starts the request for initializing device resources for Share Engine.

Function Declaration

int InitShare Kit(void* handle)

Parameter

void*

handle

  • void * type
  • Extended parameter, which is not used currently.

Return Value

int

0: success; other values: failure

[h2]Registering a Callback

Notify the user of the preview of files to receive by Share Engine.

Function Declaration

typedef void (*ShareFilePreviewCallback)(const char** fileNames, int fileNum)

Parameter

const char**

fileNames

List of files to receive

Parameter

int

fileNum

Number of the files to receive

Return Value

void

NA

Notify the user of the file transfer result (success or failure).

Function Declaration

typedef void (*ShareFileFinishCallback)(int result, const char** failedFileNames, int failedFileNum)

Parameter

int

result

File transfer result. The value 0 indicates success, and other values indicate failure.

Parameter

const char**

failedFileNames

List of the files that fail to be received.

Parameter

int

failedFileNum

Number of the files that fail to be received.

Return Value

void

N/A

[h2]Accepting the File Transfer Request

Instruct Share Engine to receive files and store them to the specified path, after the user chooses to accept the file transfer request.

Function Declaration

int ConfirmFileRecv(char *path)

Parameter

char *

path

File storage path

Return Value

int

0: success; other values: failure

[h2]Rejecting the File Transfer Request

Call this API to send a reject notification after the user chooses to reject the file transfer request.

Function Declaration

void RefuseRecvFile(void)

Return Value

void

N/A

[h2]Unregistering Share Engine

Release the system resources occupied by Share Engine.

Function Declaration

int UninitShare Kit(void)

Return Value

int

0: success; other values: failure

For details about the APIs, please refer to the API Reference.

For details about the code example, please refer to the Sample Code.