NOTE - As of Knox 3.0, the preferred way to call Knox APIs is to upgrade an Android Work Profile to a Knox Workspace. This tutorial uses Android's Device Manager to call Knox APIs. See Upgrade Android Work Profile to Knox Workspace for more information.

Activate your Knox License

The following instructions describe how to get a license key and activate it within your app.

Knox Platform for Enterprise License Key

Before you can use the Knox SDK in your app, you need to obtain a Knox Platform for Enterprise license key.

Why do you need a license? Samsung Knox uses a license manager server to identify and authenticate apps that can take control of devices. You use your KPE key in your app for authentication purposes. Your KPE key is passed to every device that you manage with your app. If your license key become is compromised, Samsung can revoke it, and apps that use the compromised key are prevented from controlling any devices.

For the purpose of this tutorial, we are using the KPE Development key because we are calling the restriction policy setCameraState.

Get a license key

  1. Request a license from the Knox Partner Program dashboard's License Keys page.
  1. Select a Development key type, which you can use during pre-production on a limited number of devices for a limited time period. You can optionally generate a backwards compatible key and REST API key.
  2. Enter a key alias, for example, MDMKEY.
  3. For added security, you can associate your app with this license key. Only this app will be allowed to activate it. This is optional during development - you only need to associate your app for commercial deployment.
  4. Click GET LICENSE KEY. The Samsung Knox Partner Program SDK and license agreements appear.
  5. After you agree to the terms, you will be taken to a page to review your key(s). Keep them secure.

Create the License Receiver class

In your app, create a new class called This contains a license receiver for the license key and backwards-compatible key.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;


public class SampleLicenseReceiver extends BroadcastReceiver {

    private int DEFAULT_ERROR_CODE = -1;

    private void showToast(Context context, int msg_res) {
        Toast.makeText(context, context.getResources().getString(msg_res), Toast.LENGTH_SHORT).show();

    private void showToast(Context context, String msg) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();

    public void onReceive(Context context, Intent intent) {

        int msg_res = -1;

        if (intent == null) {
            // No intent action is available
            showToast(context, R.string.no_intent);
        } else {
            String action = intent.getAction();
            if (action == null) {
                // No intent action is available
                showToast(context, R.string.no_intent_action);
            }  else if (action.equals(KnoxEnterpriseLicenseManager.ACTION_LICENSE_STATUS)) {
                // License key activation result Intent is obtained
                int errorCode = intent.getIntExtra(KnoxEnterpriseLicenseManager.EXTRA_LICENSE_ERROR_CODE, DEFAULT_ERROR_CODE);

                if (errorCode == KnoxEnterpriseLicenseManager.ERROR_NONE) {
                    // License key activated successfully
                    showToast(context, R.string.license_key_activated_successfully);
                    Log.d("SampleLicenseReceiver", context.getString(R.string.license_key_activated_successfully));
                } else {
                    // License key activation failed
                    switch (errorCode) {
                        case KnoxEnterpriseLicenseManager.ERROR_INTERNAL:
                            msg_res = R.string.err_license_internal;
                        case KnoxEnterpriseLicenseManager.ERROR_INTERNAL_SERVER:
                            msg_res = R.string.err_license_internal_server;
                        case KnoxEnterpriseLicenseManager.ERROR_INVALID_LICENSE:
                            msg_res = R.string.err_licence_invalid_license;
                        case KnoxEnterpriseLicenseManager.ERROR_INVALID_PACKAGE_NAME:
                            msg_res = R.string.err_license_invalid_package_name;
                        case KnoxEnterpriseLicenseManager.ERROR_LICENSE_TERMINATED:
                            msg_res = R.string.err_license_licence_terminated;
                        case KnoxEnterpriseLicenseManager.ERROR_NETWORK_DISCONNECTED:
                            msg_res = R.string.err_license_network_disconnected;
                        case KnoxEnterpriseLicenseManager.ERROR_NETWORK_GENERAL:
                            msg_res = R.string.err_license_network_general;
                        case KnoxEnterpriseLicenseManager.ERROR_NOT_CURRENT_DATE:
                            msg_res = R.string.err_license_not_current_date;
                        case KnoxEnterpriseLicenseManager.ERROR_NULL_PARAMS:
                            msg_res = R.string.err_license_null_params;
                        case KnoxEnterpriseLicenseManager.ERROR_UNKNOWN:
                            msg_res = R.string.err_license_unknown;
                        case KnoxEnterpriseLicenseManager.ERROR_USER_DISAGREES_LICENSE_AGREEMENT:
                            msg_res = R.string.err_license_user_disagrees_license_agreement;
                            // Unknown error code
                            String errorStatus = intent.getStringExtra(KnoxEnterpriseLicenseManager.EXTRA_LICENSE_STATUS);
                            String msg = context.getResources().getString(R.string.err_license_code_unknown, Integer.toString(errorCode), errorStatus);
                            showToast(context, msg);
                            Log.d("SampleLicenseReceiver", msg);

                    // Display license key error message
                    showToast(context, msg_res);
                    Log.d("SampleLicenseReceiver", context.getString(msg_res));

Register the License Receiver class

When the license is validated, the intent is emitted. The app uses the SampleLicenseReceiver class to intercept this intent.

Paste this code in AndroidManifest.xml to define the receiver for intents:

<receiver android:name="" >
		<action android:name="" />

When your app receives a intent, it passes the intent SampleLicenseReceiver.onReceive(). This method is where you can have your app respond to the license being activated.

Activate the license

Use these methods in your MainActivity to activate the license.

private void activateLicense() {
	// Instantiate the KnoxEnterpriseLicenseManager class to use the activateLicense method
	KnoxEnterpriseLicenseManager licenseManager = KnoxEnterpriseLicenseManager.getInstance(this);

	try {
	     // License Activation TODO Add KPE license key to
	} catch (Exception e) {
	     mUtils.processException(e, TAG);

When you launch the app for the first time and activate the license, you will see a Samsung confirmation dialog. This only appears once per license activation. Agree to the terms and conditions and tap CONFIRM.

Tutorial Progress

You are 7/9 done! Go to the next step.