Android for work - How do I check if my application is working in my work profile?

I am creating an application that should behave differently if it works in a work profile.

Is there any way to find out?

There is nothing about this in the documentation, and I already tried to add a restriction that is available only in the work profile, and it works, but I need a solution without any action from the administrator.

Android for work info: http://www.android.com/work/

Android for working documentation: https://developer.android.com/training/enterprise/index.html

+6
source share
1 answer

I found a solution: if isProfileOwnerApp returns true for a single package name, this means that your application (badged) is running on a working profile. if your application runs in normal mode (no icon) isProfileOwnerApp returns false for all administrators, even if there is a working profile.

DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); List<ComponentName> activeAdmins = devicePolicyManager.getActiveAdmins(); if (activeAdmins != null){ for (ComponentName admin : activeAdmins){ String packageName= admin.getPackageName(); Log.d(TAG, "admin:"+packageName); Log.d(TAG, "profile:"+ devicePolicyManager.isProfileOwnerApp(packageName)); Log.d(TAG, "device:"+ devicePolicyManager.isDeviceOwnerApp(packageName)); } } 
+8
source

Source: https://habr.com/ru/post/987871/


All Articles