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

前端 未结 1 1174
迷失自我
迷失自我 2020-12-10 13:47

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 noth

相关标签:
1条回答
  • 2020-12-10 14:25

    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));
       }
    }
    
    0 讨论(0)
提交回复
热议问题