MDM Engine enables in-depth management of Huawei devices for authorized apps.
In this codelab, you will create a demo project, integrate the MDM Engine SDK into the project, and call the APIs provided by MDM Engine to implement security management on the mobile device and apps.
In this codelab, you will learn how to:
The MDM APIs can be used only after permissions are granted. For details about the authorization, please refer to Preparations.
buildscript {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
}
dependencies {
compileOnly 'com.huawei.mdm:mdmkit:11.1.0.310'
}
For example, the following example shows how to call the APIs for disabling Wi-Fi and screenshot.
private class SampleOnClickListener implements OnClickListener {
@Override
public void onClick(View view) {
try {
switch (view.getId()) {
case R.id.disableWifi:
mDeviceRestrictionManager.setWifiDisabled(mAdminName, true);
break;
case R.id.enableWifi:
mDeviceRestrictionManager.setWifiDisabled(mAdminName, false);
break;
case R.id.disableScreenCapture:
mDeviceRestrictionManager.setScreenCaptureDisabled(mAdminName, true);
break;
case R.id.enableScreenCapture:
mDeviceRestrictionManager.setScreenCaptureDisabled(mAdminName, false);
break;
......
default:
break;
}
} catch (NoSuchMethodError error) {
Toast.makeText(getApplicationContext(), getString(R.string.not_support), Toast.LENGTH_SHORT).show();
} catch (SecurityException securityException) {
Toast.makeText(getApplicationContext(), getString(R.string.no_permission), Toast.LENGTH_SHORT).show();
}
updateState();
}
For example, add the permissions required for the MDM Engine APIs called in the preceding steps.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.mdm.sample">
<uses-permission android:name="com.huawei.permission.sec.MDM" />
<uses-permission android:name="com.huawei.permission.sec.MDM_WIFI" />
<uses-permission android:name="com.huawei.permission.sec.MDM_CAPTURE_SCREEN" />
......
</manifest>
For details, please refer to Preparations.
After the authorized APK is installed on the Huawei device, you can view the running results.
Well done. You have successfully completed this codelab and learned how to:
For more information, please click the following link:
Sample Code