Skip to content

Instantly share code, notes, and snippets.

@RamitPahwa
Created July 27, 2021 09:37
Show Gist options
  • Save RamitPahwa/060393cf7b393de9f9fd870925d19006 to your computer and use it in GitHub Desktop.
Save RamitPahwa/060393cf7b393de9f9fd870925d19006 to your computer and use it in GitHub Desktop.
For medium article on Android Enterprise
public boolean isAFWManagedApp(Context context)
{
boolean isAFWManaged = false;
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
List<ComponentName> activeAdmins = devicePolicyManager.getActiveAdmins();
if (activeAdmins != null)
{
for (ComponentName admin : activeAdmins)
{
String packageName= admin.getPackageName();
isAFWManaged = devicePolicyManager.isProfileOwnerApp(packageName);
if (isAFWManaged)
{
break;
}
}
}
return isAFWManaged;
}
public boolean isAFWManagedDevice(Context context)
{
boolean isAFWManaged = false;
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
isAFWManaged = devicePolicyManager.isDeviceOwnerApp(context.getPackageName());
return isAFWManaged;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment