Menu

Create Android Profile owner

This section shows you how to create an Android Work profile on a Samsung Knox device.

This is activated when you press CREATE MANAGED PROFILE.

Creating an Android P.O is simple and only requires 2 steps:

  1. Create the SampleAdminReciever class
  2. Create the CreateAndroidProfile() method

SampleAdminReciever class

Create a class called SampleAdminReciever, as shown below:

import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class SampleAdminReceiver extends DeviceAdminReceiver {

    void showToast(Context context, CharSequence msg) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onEnabled(Context context, Intent intent) {
        showToast(context, "Device admin enabled");
    }

    @Override
    public void onDisabled(Context context, Intent intent) {
        showToast(context, "Device admin disabled");
    }

    @Override
    public void onProfileProvisioningComplete(Context context, Intent intent) {
        showToast(context, "Profile Provisioning Complete");
        DevicePolicyManager myDevicePolicyMgr = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        ComponentName mDeviceAdmin = new ComponentName(context.getApplicationContext(), SampleAdminReceiver.class);
        myDevicePolicyMgr.setProfileName(mDeviceAdmin, "My New Work Profile");
        myDevicePolicyMgr.setProfileEnabled(mDeviceAdmin);
        myDevicePolicyMgr.enableSystemApp(mDeviceAdmin,"com.sec.android.app.camera");
    }
}

CreateAndroidProfile method

This method creates the Android Profile. When it runs, it uses the SampleAdminReciever class to complete the profile creation.

// Provision an Android Profile Owner
    private void createAndroidProfile() {

        Activity provisioningActivity = this;
        // Set up the provisioning intent
        Intent provisioningIntent = new Intent("android.app.action.PROVISION_MANAGED_PROFILE");
        provisioningIntent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,getPackageName());
        if (provisioningIntent.resolveActivity(provisioningActivity.getPackageManager()) == null) {
            // No handler for intent! Can't provision this device.
            // Show an error message and cancel.
        } else {
            // REQUEST_PROVISION_MANAGED_PROFILE is defined
            startActivityForResult(provisioningIntent, 1);
            provisioningActivity.finish();
        }
    }

Tutorial Progress

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

Share it: