HUAWEI Enterprise Manager (HEM) is a mobile device management solution provided for you based on the powerful platform and hardware of Huawei. The device deployment service in HEM helps you automatically install a Device Policy Controller (DPC) app on enterprise devices in batches.
To equip your DPC app to quickly integrate this service, Huawei offers the HEM SDK. It enables you to flexibly adapt your app to a wide range of device deployment scenarios for enterprises, to implement auto-deployment when they enroll a bunch of devices out of the box. This, in turn, dramatically reduces the required manual workload.
In this codelab, you will create a DPC app.
The app will integrate the HEM SDK to activate or deactivate a Mobile Device Management (MDM) license for your DPC app.
In this codelab, you will learn how to:
A not-activated enterprise-oriented Huawei phone or tablet (running HarmonyOS 2.0 or later). The bring your own device (BYOD) mode is not supported.
To integrate HEM Kit, you must complete the following preparations:
buildscript {
repositories {
google()
jcenter()
// Configure the Maven repository address for the HEM SDK.
maven { url 'https://developer.huawei.com/repo/' }
}
...
}
allprojects {
repositories {
google()
jcenter()
// Configure the Maven repository address for the HEM SDK.
maven { url 'https://developer.huawei.com/repo/' }
}
}
dependencies{
implementation'com.huawei.hms:hemsdk:{version}
}
, Sync Now, or Sync Project with Gradle Files to build a project.
...
private HemLicenseManager hemInstance;
...
private void onCreate() {
...
hemInstance = HemLicenseManager.getInstance(this);
...
}
<Button
android:id="@+id/active"
android:text="call active"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/de_active"
android:text="call de_active"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
In the MainActivity.java file, call the activeLicense or deActiveLicense API to activate or deactivate the license.
...
private Button buttonActive;
private Button buttonDeActive;
...
private void setButtonClickListener() {
buttonActive = findViewById(R.id.active);
buttonDeActive = findViewById(R.id.de_active);
textResultCode = findViewById(R.id.result_code);
textResultCodeDesc = findViewById(R.id.result_code_desc);
buttonActive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Activate the license.
hemInstance.activeLicense();
}
});
buttonDeActive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Deactivate the license.
hemInstance.deActiveLicense();
}
});
}
<TextView
android:id="@+id/result_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@null"
android:drawablePadding="10dp"
android:padding="10dp"
android:text="" />
b) Create an HemLicenseStatusListener class in the MainActivity.java file to listen for the status.
private void setStatusListener() {
hemInstance.setStatusListener(new MyHemLicenseStatusListener());
}
// Set the result code and description of the activation or deactivation.
private class MyHemLicenseStatusListener implements HemLicenseStatusListener {
@Override
public void onStatus(final int errorCode, final String msg) {
textResultCode.post(new Runnable() {
@Override
public void run() {
textResultCode.setText(String.valueOf(errorCode));
}
});
textResultCodeDesc.post(new Runnable() {
@Override
public void run() {
textResultCodeDesc.setText(msg);
}
});
}
Well done. You have successfully completed this codelab and learned how to:
For more information, please click the following links:
To download the sample code, please click the button below: