Back to top

Create Android profile owner

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

ProvisioningSetupApp

AndroidProfileUI

When you tap CREATE MANAGED PROFILE, the profile is activated.

PreSetupApp

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

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

Create the SampleAdminReceiver class

Create a class called SampleAdminReceiver, 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");
    }
}

Create the createAndroidProfile method

This method generates the Android profile. When it runs, it uses the SampleAdminReceiver class to complete the profile creation.

// Provision an Android profile owner
    private void createAndroidProfile() {
        Activity provisioningActivity = this;
        ComponentName deviceAdmin = new ComponentName(MainActivity.this, SampleAdminReceiver.class);
        // Set up the provisioning intent
        Intent provisioningIntent = new Intent("android.app.action.PROVISION_MANAGED_PROFILE");
        provisioningIntent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, deviceAdmin);

        if (provisioningIntent.resolveActivity(provisioningActivity.getPackageManager()) == null) {
            // No handler for intent! Can't provision this device.
            // Show an error message and cancel.
            mUtils.log(getResources().getString(R.string.provision_work_profile_failed));
        } else {
            // REQUEST_PROVISION_MANAGED_PROFILE is defined
            startActivityForResult(provisioningIntent, ACTIVITY_REQUEST_CODE);
            provisioningActivity.finish();
        }
    }

Tutorial progress

You’ve completed 3/6 steps!

Next

Is this page helpful?