目录

Service Introduction

HUAWEI OneHop Engine is a core part of Huawei's device distributed technology. Based on the traditional NFC technology, OneHop Engine integrates more short-distance technologies to enable more efficient one-tap interaction and collaboration between a phone and other devices. OneHop Engine is open to app developers and device manufacturers.

For app developers: Via OneHop Engine, you can enable app data and status synchronization between devices, such as editing a document synced from a phone on a tablet.

For device developers: You can integrate OneHop Engine's quick operations preset on Huawei phones to achieve one-step operation, such as OneHop projection and OneHop printing.

Cross-Device Quick Operations Development

This guide is oriented to device manufacturers.

Development Procedure

The steps for triggering OneHop shortcuts are as follows:

  1. Select the device type.
  2. Select the OneHop shortcut that is supported by the device.
  3. Download and integrate the OneHop development package on the device.
  4. Check that the NFC can work well.
  5. Test and complete the certification.

Developing the OneHop Printing Feature

The following figure shows the overall development process.

Note:

Sample Code

int main()
{
    signal(SIGINT, p_exit);
    InitCallback();
    InitDriverAdapt();
    /* Service Initialization APIs*/
    if (InitOneHop(NULL) != 0) {
        printf("*****Init OneHop failed!*****\n");
        return -1;
    }
    /* OneHop service is running
    * Press Ctrl and C keys to terminate the service
    */
    while (g_running) {
        if (g_serviceEndFlag == SERVICE_STOPPED) {
            g_serviceEndFlag = SERVICE_STARTED;
            printf("#####Start onehop service#####\n");
            if (StartOneHopService(&g_callBack) != 0) {
                printf("*****Start onehop service failed!*****\n");
                if (StopOneHopService() != 0) {
                    printf("*****Stop onehop service failed!*****\n");
                    UninitOneHop();
                    return -1;
                }
                g_serviceEndFlag = SERVICE_STOPPED;
            }
        }
        sleep(1);
    }
    /* Invoke the end OneHop service API */
    printf("#####Stop onehop service#####\n");
    if (StopOneHopService() != 0) {
        printf("*****Stop onehop service failed!*****\n");
        UninitOneHop();
        return -1;
    }
    /* Invoke the deinitialization OneHop service API */
    printf("#####Uninit onehop kit#####\n");
    UninitOneHop();
    return 0;
}

Note: For details on the code sample description, refer to Sample Code. For details on the API description, refer to API Reference.

NFC Tag Handling and Data Parsing

NFC tag handling: Not required for app developers. NFC tags are distributed with hardware devices and are deployed and promoted by device manufacturers.

Data format parsing: Not required for the app developers. The system will automatically parse the OneHop data in the NFC tag and trigger the corresponding operation procedure.

Common Errors

FAQs

  1. Failure to call the StartOneHopService API: From the aspect of hardware, check that the Wi-Fi module can work well and the Wi-Fi is enabled. In terms of software, check that the installed wpa_supplicant version is correct.
  2. Failure to call the OneHopConfirmRecv API: Check that the length of the parameters that are used to call the API meets the requirement. For details, refer to the parameter description in API Reference.