目录

1. HUAWEI OneHop Kit Development Guide

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


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

For device developers: They can integrate the OneHop shortcut preset on Huawei smartphones to achieve one-step operation, such as OneHop projecting and OneHop printing.

2. Development Guide on Cross-Device App Synchronization

This guide is for app developers.

2.1 Cross-device App Synchronization Procedure

Cross-device app synchronization involves the integration and adaptation of the apps on the mobile phone and the tablet. Currently, only supported on the Huawei smartphones and tablets.


The following figure shows the overall process.


The app integration process on the smartphone is as follows:


Preparation: Ensure that the app on the smartphone is running in the foreground to trigger the HUAWEI OneHop service.


The app integration process on the tablet is as follows:

Preparation: The app on the tablet is not required to run in the foreground. After receiving the data synced from the mobile phone, the tablet system automatically starts the corresponding app. If the app is not installed on the tablet, the system will prompt the user to go to HUAWEI AppGallery to download it.


2.2 API Description

2.2.1 Development Package Description

OneHop Kit and the HwOneHopSDK class used to implement the APIs, are contained in a JAR package. The member functions of the HwOneHopSDK class can be invoked by certain apps.

2.2.2 Class Description

  1. import com.huawei.onehop.appsdk.HwOneHopSdk;
  2. import android.emcom.IOneHopSdkCallback;

The HwOneHopSdk class is implemented in the form of a single instance. The instance is obtained through the getInstance() method. For example, HwOneHopSdk. getInstance().registerOneHop();

Code snippet 1: Implementing the listening API ServiceCallBack

  1. public class ServiceCallBack implements IOneHopSdkCallback.Stub {
  2.      public void onOneHopReceived (String para) {
  3.       //Call the OneHop API OneHopData to notify the current tapping event.
  4.       JSONObject jsonObject = new JSONObject(para);
  5.       //Parse the JSON data and process it…
  6. }


Code snippet 2: Registering ServiceCallBack with OneHopSDK

  1. int retcode;
  2. String packageName = "com.android.example";
  3. ServiceCallBack  servicecallback = new ServiceCallBack();
  4. retcode = HwOneHopSdk.getInstance().registerOneHop(packageName, HwOneHopSdk.ONEHOP_DATA_TYPE_BUSINESS_CONTINUITY, servicecallback);
  5. if (HwOneHopSdk.ONEHOP_ERR == retcode) {
  6.      Log.e("OneHop", "register OneHop error.");
  7. }

Invoking time: When the OneHop SDK uses the onOneHopReceived() callback API registered by the app to notify the app of data synchronization, the app invokes this API to sync data.

Code snippet 1: OneHop data synchronization

  1. //oneHopSend
  2. int retcode;
  3. String packageName = "com.android.example";
  4. String param={"para1":"xxxxxx", "para2":xxx};
  5. JSONObject obj = new JSONObject(param);
  6. retcode  = HwOneHopSdk.getInstance().oneHopSend (packageName , obj);


JSON format description:

Table 1: Description of the preset key values

Name

Value

Description

ONEHOP_DATA_TYPE

"onehop_data_type"

The data type of OneHop

ONEHOP_RECEIVE_TYPE

"onehop _reveive_type"

The data type of onOneHopReceived

Table 2 : Value description of ONEHOP_DATA_TYPE

Name

Sub Type

Value

Description

ONEHOP_DATA_TYPE

ONEHOP_DATA_TYPE_BUSINESS_CONTINUITY

7

Service connection

Table 3:  Value description of ONEHOP_DATA_TYPE

Name

Sub Type

Value

Description

ONEHOP_RECEIVE_TYPE

event

1

Triggering event

data

2

Service data


Parameters in JSON format:

{"OneHop_data_type":7, "onehop _reveive_type":1}

{"OneHop_data_type":7, "onehop _reveive_type":2, "xxx":"xxx", ...}

Here "xxx" refers to the service data.

{"OneHop_data_type":7, "xxx":"xxx", ...}

Here "xxx" refers to the service data.


Permission description

To use the OneHop Kit API, you need to add the following permission to the manifest.xml file of the APK to pass the permission verification:

<uses-permission android:name="com.huawei.permission.ONEHOP"/>


Other APIs

For details, see the section about API reference.

2.2.3 NFC Tag Handling and Data Parsing

NFC tag handling: Not required for app developers. NFC tags are programmed and attached by hardware vendors and distributed with hardware devices.

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.