Java Code Examples for android.app.admin.DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE

The following examples show how to use android.app.admin.DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Shelter with Do What The F*ck You Want To Public License 6 votes vote down vote up
private void setupProfile() {
    // Build the provisioning intent first
    ComponentName admin = new ComponentName(getApplicationContext(), ShelterDeviceAdminReceiver.class);
    Intent intent = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
    intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION, true);
    intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, admin);

    // Check if provisioning is allowed
    if (!mPolicyManager.isProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE)
            || getPackageManager().resolveActivity(intent, 0) == null) {
        Toast.makeText(this,
                getString(R.string.msg_device_unsupported), Toast.LENGTH_LONG).show();
        finish();
    }

    // Start provisioning
    startActivityForResult(intent, REQUEST_PROVISION_PROFILE);
}
 
Example 2
Source File: SetupProfileFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Initiates the managed profile provisioning. If we already have a managed profile set up on
 * this device, we will get an error dialog in the following provisioning phase.
 */
private void provisionManagedProfile() {
    Activity activity = getActivity();
    if (null == activity) {
        return;
    }
    Intent intent = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);

    // Use a different intent extra below M to configure the admin component.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        intent.putExtra(
                DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
                activity.getApplicationContext().getPackageName()
        );
    } else {
        final ComponentName component = new ComponentName(activity,
                BasicDeviceAdminReceiver.class.getName());
        intent.putExtra(
                DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
                component
        );
    }

    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_PROVISION_MANAGED_PROFILE);
        activity.finish();
    } else {
        Toast.makeText(activity, "Device provisioning is not enabled. Stopping.",
                Toast.LENGTH_SHORT).show();
    }
}
 
Example 3
Source File: SetupProfileFragment.java    From android-BasicManagedProfile with Apache License 2.0 5 votes vote down vote up
/**
 * Initiates the managed profile provisioning. If we already have a managed profile set up on
 * this device, we will get an error dialog in the following provisioning phase.
 */
private void provisionManagedProfile() {
    Activity activity = getActivity();
    if (null == activity) {
        return;
    }
    Intent intent = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);

    // Use a different intent extra below M to configure the admin component.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        //noinspection deprecation
        intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
                activity.getApplicationContext().getPackageName());
    } else {
        final ComponentName component = new ComponentName(activity,
                BasicDeviceAdminReceiver.class.getName());
        intent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME,
                component);
    }

    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_PROVISION_MANAGED_PROFILE);
        activity.finish();
    } else {
        Toast.makeText(activity, "Device provisioning is not enabled. Stopping.",
                       Toast.LENGTH_SHORT).show();
    }
}