Overview

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.

What You Will Create

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.

What You Will Learn

In this codelab, you will learn how to:

Hardware Requirements

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.

Software Requirements

To view the HMS Core (APK) version on a device, go to Settings > Apps > Apps and search for HMS Core.

To integrate HEM Kit, you must complete the following preparations:

Configuring the HEM SDK Repository and Dependency Package

  1. Configure the Maven repository address in the project-level build.gradle file.
    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/' } } }
  2. Configure the dependency package in the build.gradle file in the app directory.
    dependencies{ implementation'com.huawei.hms:hemsdk:{version} }
  3. Click , Sync Now, or Sync Project with Gradle Files to build a project.
  1. Before using the HEM SDK, you need to apply for an MDM license. For details, please refer to EMM Provider Operation Guide.
  2. Create a license manager in MainActivity.java for activation and deactivation.
    ... private HemLicenseManager hemInstance; ... private void onCreate() { ... hemInstance = HemLicenseManager.getInstance(this); ... }
  3. Create buttons for triggering activation and deactivation in the activity_main.xml file.
    <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(); } }); }
  4. Obtain the status.
    a) Create a TextView in the activity_main.xml file to display the status.
    <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:

    • Integrate the HEM SDK.
    • Activate and deactivate an MDM license.

    For more information, please click the following links:

    To download the sample code, please click the button below:

    Download

    Code copied