1. Introduction
As a cross-device file transfer solution, HUAWEI Share Engine uses Bluetooth to discover nearby devices and authenticate connections, then sets up Wi-Fi peer-to-peer channels to allow file transfers between phones, PCs, and other devices. File transfer speeds can reach 80 Mbps if the third-party device and environment allow.
The Share Engine capabilities are sealed deep in the package, and are open to developers of apps and smart devices. By integrating these capabilities, printers, cameras, and other compatible devices can easily share files with each other.
Three SDK development packages are offered to allow integration for Android, Linux, and Windows based apps and devices.
In this codelab, you will learn how to integrate Share Engine on Linux devices. When the integration is successful, images can be transferred between Linux devices and Huawei devices.
What You Will Create
In this codelab, you will create a demo project, integrate the Share Engine SDK into the demo project, and complete the overall setup of the Share Engine service.
- Schematic drawing
What You Will Learn
- How to enable the Share Engine service.
- How to build a sample app and integrate the Share Engine SDK into the app.
- How to complete the overall setup of the Share Engine service.
2. What You Will Need
Hardware Requirements
- A Huawei phone with a USB port and running EMUI 9.0 or later, which is used for developing and debugging the sample app
- A third-party device that runs Linux (Ubuntu 18.04 is recommended), which is used for developing and debugging the sample app
Software Requirements
- OpenSSL 1.1.1g
- BlueZ 5.52 Bluetooth protocol stack (other protocol stacks need adaptation) and wpa_supplicant support
- X86_64 or Arm64 architecture
Required Knowledge
- Linux app development basics
- Linux multithreading
- Wi-Fi and Bluetooth development basics
3. Integration Preparations
To integrate Share Engine, you must complete the following preparations:
- Register a HUAWEI ID and complete identity verification.
- Obtain the Share Engine SDK.
- Prepare and set up the environment. For details, please refer to Integration Preparations.
4. Development Procedure
Creating a Project
The specific procedure depends on the actual development environment. The sample code includes the southbound API adaptation reference and a demo for calling the APIs.
Reference documents:
- Linux Device Integration Development Guide
- API Description for Integrating Share Engine into Linux Device
- Sample Code for Integrating Share Engine into Linux Device
Installing BlueZ 5.52 and wpa_supplicant
1. Install BlueZ 5.52.
Download BlueZ 5.52 at http://www.bluez.org/.
Install BlueZ 5.52. For example, perform compilation from bottom to top based on the following dependencies:
bluez-5.52
|——–readline-8.0
|——–ncurses-6.1
|——–libxml2-2.9.9
|——–libical-3.0.6
|——–dbus-1.13.4
|—-glib-2.58.3
|—-zlib-1.2.11
|—-expat-2.2.9
|—-pcre3_8.39
|—-libffi-3.2.1
|—-util-linux_2.31.1
2. Install wpa_supplicant.
Download wpa_supplicant at https://w1.fi/wpa_supplicant/.
Install wpa_supplicant. The following is for reference:
a. Install libnl and OpenSSL.
b. Decompress the wpa_supplicant package.
c. Run cp .config wpa_supplicant-2.9/wpa_supplicant.
d. Run cd wpa_supplicant-2.9/wpa_supplicant.
e. Run export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/libnl/lib.
f. Run make BINDIR=/sbin LIBDIR=/lib -j8.
g. Run install -v -m755 wpa_{cli,passphrase,supplicant} /sbin/.
Configuring Environment Variables
Refer to the makefile in the sample code.
Sample Code Description
After the environment variables are configured, you are ready to compile the sample code.
1. Receiving device: For details about the sample code, please refer to sharekit_demo_rx.c.
Callback Function | Description |
SharekitProcessCbFunc | Returns the transfer progress. |
SharekitStatusChangeCbFunc | Returns the status changes. |
RequestFileTrans | Previews the names and quantity of received files. |
FileTransferResult | Returns the transfer result. (This function is reserved). |
The API calling procedure is as follows:
a. Call InitShareKit to initialize Share Engine.
b. Call StartShareService to start the Share Engine service.
c. After the file transfer is complete, call StopShareService to stop the Share Engine service.
d. Call UninitShareKit to release resources when exiting the process.
2. Sending device: For details about the sample code, please refer to sharekit_demo_tx.c.
Callback Function | Description |
SharekitProcessCbFunc | Returns the transfer progress. |
SharekitStatusChangeCbFunc | Returns the status changes. |
FileTransferResult | Returns the transfer result. (This function is reserved). |
The API calling procedure is as follows:
a. Call ScanFileName to select files to be sent.
b. Call InitShareKit to initialize Share Engine.
c. Call StartShareService to start the Share Engine service. At this time, the device starts to scan for the receiving device through Bluetooth.
d. Call SelectDev to select the receiving device.
e. Call TransFile to send the files.
f. After the file transfer is complete, call StopShareService to stop the Share Engine service.
g. Call UninitShareKit to release resources when exiting the process.
Running the Demo Project
Perform the following steps:
1. On the receiving device:
a. Run the sharekit_demo_rx process. The following figure shows part of the running log, which indicates that the receiving device has been detected by the sending device.
b. The sending device user selects the files to send, touches the share button, and selects Huawei Share, as shown in the following figure.
c. The receiving device receives the files. The following figure shows the running log.
2. On the sending device:
a. Start the sharekit_demo_tx process. The following figure shows part of the running log.
b. The sending device starts scanning immediately after the preceding process starts. The following figure shows the running log.
c. Ensure that Huawei Share has been enabled on the phone. Select the device from which you want to receive the files. A confirmation dialog box will be displayed on the phone, as shown in the following figure.
d. The sending device sends the files successfully, as shown in the following figure.
5. Congratulations
Well done. You have successfully completed this codelab and learned how to:
- Enable the Share Engine service.
- Build a sample app and integrate the Share Engine SDK into the app.
- Complete the overall setup of the Share Engine service.
6. Reference
For more information, please click the following links:
- Share Engine Service Introduction
- API Description for Integrating Share Engine into Linux Device
- Sample Code for Integrating Share Engine into Linux Device
To download the sample code, please click the button below: