Programmatically check 'Work Profile' support in android

1.5k views Asked by At

I would like to check whether the device is supporting "Work Profile" pr not via code

Noticed that Native Support for "Work profile" from Android 5.0+ though on HTC device it is not supporting.

Could anyone share how to achieve this...

2

There are 2 answers

0
Reaper On

For anyone reading this, I thought that checking FEATURE_MANAGED_USERS was sufficient, but in some devices you need to check too if there is anyone who will resolve the managed provisioning intent.

public boolean isManagedProvisioningAvailable() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return false;
    }
    PackageManager pm = getApplicationContext().getPackageManager();
    if (!pm.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS)) {
        return false;
    }
    Intent intent = new Intent(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
    ComponentName resolved = intent.resolveActivity(pm);
    return resolved != null;
}
0
Steve Miskovetz On

Android must have the hardware feature android.software.managed_users declared. It can be checked

PackageManager pm = getPackageManager();
   if (!pm.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS)) {
      // This device does not support work profiles!
   }

https://developer.android.com/reference/android/content/pm/PackageManager.html https://developers.google.com/android/work/build-dpc