Example usage for android.app.admin DevicePolicyManager getActiveAdmins

List of usage examples for android.app.admin DevicePolicyManager getActiveAdmins

Introduction

In this page you can find the example usage for android.app.admin DevicePolicyManager getActiveAdmins.

Prototype

public @Nullable List<ComponentName> getActiveAdmins() 

Source Link

Document

Return a list of all currently active device administrators' component names.

Usage

From source file:Main.java

/**
 * @return true if the device or profile is already owned
 *//*from   ww  w. ja va2s  .c  om*/
public static boolean isManaged(Context context) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context
            .getSystemService(Context.DEVICE_POLICY_SERVICE);

    List<ComponentName> admins = devicePolicyManager.getActiveAdmins();
    if (admins == null)
        return false;
    for (ComponentName admin : admins) {
        String adminPackageName = admin.getPackageName();
        if (devicePolicyManager.isDeviceOwnerApp(adminPackageName)
                || devicePolicyManager.isProfileOwnerApp(adminPackageName)) {
            return true;
        }
    }

    return false;
}