Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android for work - How to check if my application is running in the work profile?

Tags:

android

I'm creating an app that needs to behave differently if it's running in the work profile.

There is any possibility to know that?

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

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

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

like image 467
jlopes Avatar asked May 25 '15 16:05

jlopes


People also ask

How do I manage my work profile app?

Open your phone's Settings app. Tap Digital Wellbeing & parental controls. Tap Work Profile and toggle Set a schedule. You will now be able to specify the hours and days of the week that work profile will automatically remain active.

Can I have 2 work profiles on Android?

You cannot have multiple work profile on one device, only one. However depending on the restrictions you might be able to add another email account in the personal profile or in the work profile.


1 Answers

I found a solution : if isProfileOwnerApp return true for one package name, it means that your app (badged) is running on work profile. if your app is running in normal mode (no badge) isProfileOwnerApp return false for all admins even if there is a Work 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));
   }
}
like image 161
earlypearl Avatar answered Oct 16 '22 22:10

earlypearl